Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.11.2, 5.12
-
None
-
OS 10.6.4. x86_64 build
-
-
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(); }