diff options
author | Stephen Kelly <stephen.kelly@kdab.com> | 2013-06-18 14:42:43 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-06-19 12:16:03 +0200 |
commit | 249c5f0689bf1208a4f1d589de45c20c3ff16de9 (patch) | |
tree | ee75b8c09e5e568b08c4b5ba67a7601a0968396d | |
parent | 2a8efea1a90436556f1cd471dce27a0619c5618e (diff) |
If a QWidget is ignored for auto-quit, ignore its corresponding QWindow.
Unit test by Friedemann Kleint <Friedemann.Kleint@digia.com>
Task-number: QTBUG-31569
Change-Id: I526d33d4f88a41f6ac349098476bc45af6c841b0
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 8 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication_p.h | 2 | ||||
-rw-r--r-- | src/widgets/kernel/qapplication.cpp | 4 | ||||
-rw-r--r-- | tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp | 25 |
4 files changed, 38 insertions, 1 deletions
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 @@ -2479,10 +2479,18 @@ 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 |