From 249c5f0689bf1208a4f1d589de45c20c3ff16de9 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 18 Jun 2013 14:42:43 +0200 Subject: [PATCH] If a QWidget is ignored for auto-quit, ignore its corresponding QWindow. Unit test by Friedemann Kleint Task-number: QTBUG-31569 Change-Id: I526d33d4f88a41f6ac349098476bc45af6c841b0 Reviewed-by: Friedemann Kleint --- src/gui/kernel/qguiapplication.cpp | 8 ++++++ src/gui/kernel/qguiapplication_p.h | 2 ++ src/widgets/kernel/qapplication.cpp | 4 ++- .../kernel/qapplication/tst_qapplication.cpp | 25 +++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index add1c1f90b..77c9978a9e 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2478,11 +2478,19 @@ void QGuiApplicationPrivate::emitLastWindowClosed() } bool QGuiApplicationPrivate::shouldQuit() +{ + const QWindowList processedWindows; + return shouldQuitInternal(processedWindows); +} + +bool QGuiApplicationPrivate::shouldQuitInternal(const QWindowList &processedWindows) { /* if there is no visible top-level window left, we allow the quit */ QWindowList list = QGuiApplication::topLevelWindows(); for (int i = 0; i < list.size(); ++i) { QWindow *w = list.at(i); + if (processedWindows.contains(w)) + continue; if (w->isVisible() && !w->transientParent()) return false; } diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index cd8dfff103..3a4b692b69 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -91,6 +91,8 @@ public: virtual bool shouldQuit(); + bool shouldQuitInternal(const QWindowList &processedWindows); + static Qt::KeyboardModifiers modifier_buttons; static Qt::MouseButtons mouse_buttons; diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 6921b4b462..080f4358f2 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -2695,12 +2695,14 @@ bool QApplicationPrivate::shouldQuit() the ones without QuitOnClose), we emit the lastWindowClosed signal */ QWidgetList list = QApplication::topLevelWidgets(); + QWindowList processedWindows; for (int i = 0; i < list.size(); ++i) { QWidget *w = list.at(i); + processedWindows.push_back(w->windowHandle()); if (w->isVisible() && !w->parentWidget() && w->testAttribute(Qt::WA_QuitOnClose)) return false; } - return QGuiApplicationPrivate::shouldQuit(); + return QGuiApplicationPrivate::shouldQuitInternal(processedWindows); } static inline void closeAllPopups() diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index c6835f6076..c9079e222c 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -783,6 +783,31 @@ void tst_QApplication::quitOnLastWindowClosed() QVERIFY(timerSpy.count() > 15); // Should be around 20 if closing did not caused the quit } + { // QTBUG-31569: If the last widget with Qt::WA_QuitOnClose set is closed, other + // widgets that don't have the attribute set should be closed automatically. + int argc = 0; + QApplication app(argc, 0); + QVERIFY(app.quitOnLastWindowClosed()); + + QWidget w1; + w1.show(); + + QWidget w2; + w2.setAttribute(Qt::WA_QuitOnClose, false); + w2.show(); + + QVERIFY(QTest::qWaitForWindowExposed(&w2)); + + QTimer timer; + timer.setInterval(100); + timer.start(); + QSignalSpy timerSpy(&timer, SIGNAL(timeout())); + + QTimer::singleShot(100, &w1, SLOT(close())); + app.exec(); + + QVERIFY(timerSpy.count() < 10); + } } class PromptOnCloseWidget : public QWidget