Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-89580

[regression 5.15 -> 6.0] QApplication::quit() no longer works within closeEvent()

    XMLWordPrintable

Details

    • All
    • e7370d0583ea8a50b0d5c15bb2b1afee2efc6a7e (qt/qtbase/dev) 254aa011b1a783d29db542ed9450be333b943133 (qt/qtbase/6.0)

    Description

      Calling QApplication::quit() from within a widget's closeEvent() no longer has any effect in Qt 6.0.0.

      The test case below, with Qt 5, quits when the window is closed. In Qt 6, QApplication::exec() does not return and the application remains running with no windows visible.

      Note: It's necessary to do setQuitOnLastWindowClosed(false) to see the issue (otherwise the application quits regardless of QApplication::quit() being called or not).

      Test case:

      #include <QApplication>
      #include <QCloseEvent>
      #include <QWidget>
      
      class MyWindow : public QWidget
      {
      public:
          void closeEvent(QCloseEvent * event) override
          {
              qApp->quit();
              event->accept();
          }
      };
      
      int main(int argc, char ** argv)
      {
          QApplication app(argc, argv);
          app.setQuitOnLastWindowClosed(false);
      
          MyWindow window;
          window.show();
      
          return app.exec();
      }
      

      Attachments

        For Gerrit Dashboard: QTBUG-89580
        # Subject Branch Project Status CR V

        Activity

          People

            vestbo Tor Arne Vestbø
            john.lindgren@aol.com John Lindgren
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes