QT的一个奇怪问题,设置了Qt::Tool后,点击弹出对话框的确定取消按钮,程序直接退出。

Alright, I found the reason. QWidget::create() clears the Qt::WA_QuitOnClose attribute for anything but Qt::Window, Qt::Widget or Qt::Dialog. The workaround is to call for example QWidget::show() first, and set the attribute by hand afterwards:

Qt Code:
#include <QtGui>
 
intmain(intargc, char*argv[])
{
QApplicationapp(argc, argv);
QMainWindowwin(0, Qt::Tool);
win.show()// must be called before setting Qt::WA_QuitOnClose
win.setAttribute(Qt::WA_QuitOnClose);
returnapp.exec();
}


原文地址:https://www.cnblogs.com/yuzhould/p/4454947.html