【问题标题】:How to create a correct exit button in qt如何在qt中创建正确的退出按钮
【发布时间】:2012-08-04 10:54:11
【问题描述】:

我正在尝试创建一个退出按钮,以正确关闭我在 QT 中制作的 GUI。我尝试通过以下方式执行此操作:

#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

int window_width = QApplication::desktop()->width();
int window_height = QApplication::desktop()->height();

MainWindow w;

QPushButton * quit_btn = new QPushButton;
quit_btn->setParent(w.centralWidget());
quit_btn->setGeometry(window_width-50,12,32,32);

QObject::connect(quit_btn,SIGNAL(clicked()),qApp,SLOT(quit()));

w.resize(window_width,window_height);
w.show();

return a.exec();
}

不幸的是,当我按下按钮时,调试器给出了错误:

Invalid address specified to RtlFreeHeap( 003E0000, 0028F950 )

谁能指出我正确的方向?

【问题讨论】:

    标签: qt user-interface button exit


    【解决方案1】:

    将按钮的clicked() 信号连接到主窗口的close() 插槽。这样就可以正确清理东西了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多