如何创建QT正确的退出按钮 [英] How to create a correct exit button in qt
本文介绍了如何创建QT正确的退出按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图创建一个退出按钮正确关闭我在QT作出的GUI。我曾尝试以下列方式这样做:
I'm trying to create an exit button that correctly closes the GUI I have made in QT. I have tried doing this in the following way:
#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();
}
不幸的是,当我按下按钮,调试器提供了一个错误:
Unfortunately when I push the button, the debugger gives an error:
Invalid address specified to RtlFreeHeap( 003E0000, 0028F950 )
任何人都可以点我在正确的方向?
Can anybody point me in the right direction?
推荐答案
按钮的点击()
信号连接到你的主窗口的的close()
插槽。事情的方式被正确地清理。
Connect the button's clicked()
signal to your main window's close()
slot. That way things are cleaned up properly.
这篇关于如何创建QT正确的退出按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文