Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem closing QDialog based tool style application
Forum Updated to NodeBB v4.3 + New Features

Problem closing QDialog based tool style application

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 595 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kegon
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Can you show a minimal sample code that shows that behaviour ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kegon
        wrote on last edited by
        #3

        Minimal example follows...

        dialogtool.pro:

        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
        

        main.cc:

        #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
        

        dialogtool.cc:

        #include "dialogtool.h"
        
        DialogTool::DialogTool() : QDialog(nullptr, Qt::Tool) { }
        DialogTool::~DialogTool() { }
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved