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

Unable to quit on mac when setQuitOnLastWindowClosed = false after last window is closed

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.12.1, 5.12.2, 6.0.0 RC
    • 5.11.2, 5.12
    • GUI: Window management
    • None
    • OS 10.6.4. x86_64 build
    • macOS
    • 10b3f2c109eb9737648c4581ad198ae8214be78d (qt/qtdoc/5.12)

    Description

      (as noted by jlarcombe in the comments - this is still reproducible in 5.11)

      If you have an application where setQuitOnLastWindowClosed = false and there is a global QMenuBar (created with a parent of NULL) and a QMenuBar in the QMainWindow, then when you close the main window the application can't be closed. It doesn't respond to the application menu's Quit command or Cmd-Q (this also affects items created with the Preferences and About menu roles).

      -------

      #include <QApplication>
      #include <QMainWindow>
      #include <QLabel>
      #include <QMenuBar>
      #include <QMenu>
      
      // To reproduce: 
      // 1. Run app
      // 2. Close main window with close button on caption bar
      // 3. Try to exit via the application menu or Cmd-Q
      //
      // EXPECTED: application quits
      // ACTUAL: unable to quit
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      	app.setQuitOnLastWindowClosed(false);
      
      	// Create the global menu which we will revert to when the QMainWindow is closed
      	QMenuBar* sharedMenuBar=new QMenuBar(0); 
      	QMenu* sharedMenu= sharedMenuBar->addMenu("Shared menu");
      	sharedMenu->addAction("Nop");
      
      	// Create an Exit menu item which will be moved to the application menu
      	QAction* exitAct = sharedMenu->addAction("E&xit");
      	exitAct->setMenuRole(QAction::QuitRole);
      	sharedMenu->addAction(exitAct);
      
      	// Workaround is to uncomment the following line:
      	// QObject::connect(exitAct, SIGNAL(triggered()), &app, SLOT(quit()));
      
      	// Now create the main window and create a simple menu for it
      	QMainWindow mainWindow;
      	QLabel* staticText=new QLabel("Hit the close button to close this window then type cmd-Q");
      	mainWindow.setCentralWidget(staticText);
      	QMenu* mainWindowFileMenu= mainWindow.menuBar()->addMenu("Window menu");
      	mainWindowFileMenu->addAction("Nop");
      
      	mainWindow.show();
      
      	return app.exec();
      }
      

      Attachments

        1. main.cpp
          1 kB
        2. qtbug-14174.zip
          1 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            sgaist Samuel Gaist
            paul_walmsley Paul Walmsley
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes