Problem closing QDialog based tool style application
-
My application uses QDialog as the base class instead of QMainWindow and I set the
Qt::Toolwindow flag. Now when I click on the close window button the window disappears but the program is still running. Now I can only quit by control click on the dock icon or through the screen menu bar.I tried setting
QApplication::setQuitOnLastWindowClosed(true), I tried callingQDialog::accept()on thecloseEvent.I want the program to quit when the window is closed. It seems a bit rude to call
exit()in the close event.On Mac, the default style is that applications don't close when the last window closes but I don't want that here.
System: OSX 10.11, Qt 5.7.1
-
Hi,
Can you show a minimal sample code that shows that behaviour ?
-
Minimal example follows...
QT += core gui CONFIG += qt c++11 warn_all greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = DialogTool TEMPLATE = app SOURCES += main.cc dialogtool.cc HEADERS += dialogtool.h#include <QApplication> #include "dialogtool.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); a.setQuitOnLastWindowClosed(true); DialogTool w; w.show(); return a.exec(); }dialogtool.h:
#ifndef dt_h #define dt_h #include <QDialog> class DialogTool : public QDialog { Q_OBJECT public: DialogTool(); ~DialogTool(); }; #endif#include "dialogtool.h" DialogTool::DialogTool() : QDialog(nullptr, Qt::Tool) { } DialogTool::~DialogTool() { } -
I can confirm the behaviour. However it indeed does look a bit strange. I'd recommend checking the but report system to see if there's anything related.