Problem closing QDialog based tool style application

  • My application uses QDialog as the base class instead of QMainWindow and I set the Qt::Tool window 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 calling QDialog::accept() on the closeEvent.

    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

  • Lifetime Qt Champion


    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 +=
    HEADERS += dialogtool.h

    #include <QApplication>
    #include "dialogtool.h"
    int main(int argc, char *argv[])
      QApplication a(argc, argv);
      DialogTool w;;
      return a.exec();


    #ifndef dt_h
    #define dt_h
    #include <QDialog>
    class DialogTool : public QDialog

    #include "dialogtool.h"
    DialogTool::DialogTool() : QDialog(nullptr, Qt::Tool) { }
    DialogTool::~DialogTool() { }

  • Lifetime Qt Champion

    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.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.