diff options
-rw-r--r-- | src/gui/kernel/qwindow.cpp | 26 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp | 27 |
2 files changed, 39 insertions, 14 deletions
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index b9dba10f22..dd4bb57690 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -2290,24 +2290,22 @@ void QWindowPrivate::maybeQuitOnLastWindowClosed() Q_Q(QWindow); // Attempt to close the application only if this has WA_QuitOnClose set and a non-visible parent bool quitOnClose = QGuiApplication::quitOnLastWindowClosed() && !q->parent(); - - if (quitOnClose) { - QWindowList list = QGuiApplication::topLevelWindows(); - bool lastWindowClosed = true; - for (int i = 0; i < list.size(); ++i) { - QWindow *w = list.at(i); - if (!w->isVisible() || w->transientParent()) - continue; - lastWindowClosed = false; - break; - } - if (lastWindowClosed) { - QGuiApplicationPrivate::emitLastWindowClosed(); + QWindowList list = QGuiApplication::topLevelWindows(); + bool lastWindowClosed = true; + for (int i = 0; i < list.size(); ++i) { + QWindow *w = list.at(i); + if (!w->isVisible() || w->transientParent()) + continue; + lastWindowClosed = false; + break; + } + if (lastWindowClosed) { + QGuiApplicationPrivate::emitLastWindowClosed(); + if (quitOnClose) { QCoreApplicationPrivate *applicationPrivate = static_cast<QCoreApplicationPrivate*>(QObjectPrivate::get(QCoreApplication::instance())); applicationPrivate->maybeQuit(); } } - } QWindow *QWindowPrivate::topLevelWindow() const diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index 310fd58b7f..b14d2cf288 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -812,6 +812,33 @@ void tst_QGuiApplication::quitOnLastWindowClosed() QCOMPARE(spy.count(), 1); QVERIFY(spy2.count() > 15); // Should be around 20 if closing did not cause the quit } + { + int argc = 0; + QGuiApplication app(argc, 0); + app.setQuitOnLastWindowClosed(false); + + QTimer timer; + timer.setInterval(2000); + timer.setSingleShot(true); + QObject::connect(&timer, SIGNAL(timeout()), &app, SLOT(quit())); + + QSignalSpy spy(&app, SIGNAL(lastWindowClosed())); + QSignalSpy spy2(&timer, SIGNAL(timeout())); + + QPointer<QWindow> mainWindow = new QWindow; + + mainWindow->show(); + + QTimer::singleShot(1000, mainWindow, SLOT(close())); // This should not quit the application + timer.start(); + + app.exec(); + + QCOMPARE(spy2.count(), 1); // quit timer fired + QCOMPARE(spy.count(), 1); // lastWindowClosed emitted + + app.setQuitOnLastWindowClosed(true); // restore underlying static to default value + } } static Qt::ScreenOrientation testOrientationToSend = Qt::PrimaryOrientation; |