summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2024-04-24 22:33:42 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2024-04-29 14:26:38 +0000
commit0b494c47d36a8234b1763518c9cddafe62f03715 (patch)
treefc51335a9d2bea347cbfe4c842d63525ba0de021 /tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
parentd93ec246c7072b7907edc86da2840ec141f745f3 (diff)
Don't quit automatically via QEventLoopLocker if there are open windows
As part of df359bcb703db5a8adbf14e88ba4ae0d54f0cfcd the semantics and interaction between QEventLoopLocker and QGuiApplication was changed, based on the assumption that these two mechanisms were independent and should not affect each other. This had a surprising regression where the use of QEventLoopLocker in combination with the QCoreApplication::isQuitLockEnabled() automatic quit would end up quitting the app, even if it had open windows, for example when the last job of some internal job queue finished. It could be argued that if the app has open windows that should not be closed, they should ignore the Close event, and that an application with running QEventLoopLocker jobs should maintain an active window showing the progress of those jobs, but still, this is regression that we want to fix. We now bail out if !lastWindowClosed() in QGuiApplication's canQuitAutomatically, which is triggered from QEventLoopLocker's isQuitLockEnabled() behavior. And we do so regardless of whether quitOnLastWindowClosed is set or not, as the latter property determines the behavior when closing a window, not the behavior when a QEventLoopLocker goes out of scope. Similarly, we now block quitting of the application when triggered by quitOnLastWindowClosed() if a QEventLoop is active, regardless of the isQuitLockEnabled(), as the latter property is determining whether we should trigger a quit, not whether we should block them. [ChangeLog][Important behavior changes] Fixed a regression where the last QEventLoopLocker going out of scope would quit the app, even if there were open windows, if quitOnLastWindowClosed was false. [ChangeLog][Important behavior changes] Fixed a regression where closing the last window would quit the app, even if there were active QEventLoopLockers, if isQuitLockEnabled was false. Fixes: QTBUG-124386 Pick-to: 6.7 6.5 Change-Id: I84fd0ddea78a2f417f3a17b326113c880079cf85 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp')
-rw-r--r--tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp42
1 files changed, 37 insertions, 5 deletions
diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
index 6b8700f580..d1a50e3d69 100644
--- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
+++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
@@ -1004,8 +1004,8 @@ void tst_QGuiApplication::quitOnLastWindowClosedWithEventLoopLocker()
});
{
- // Disabling QEventLoopLocker support should not affect
- // quitting when last window is closed.
+ // Disabling QEventLoopLocker automatic quit should not affect
+ // quitting when last window is closed if there are no lockers.
app.setQuitLockEnabled(false);
QuitSpy quitSpy;
@@ -1019,8 +1019,40 @@ void tst_QGuiApplication::quitOnLastWindowClosedWithEventLoopLocker()
}
{
- // Disabling quitOnLastWindowClosed support should not affect
- // quitting when last QEventLoopLocker goes out of scope.
+ // Disabling QEventLoopLocker automatic quit should still block
+ // quitting when last window is closed if there is a locker alive.
+ app.setQuitLockEnabled(false);
+
+ QScopedPointer<QEventLoopLocker> locker(new QEventLoopLocker);
+
+ QuitSpy quitSpy;
+ QWindow window;
+ window.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
+ QTimer::singleShot(0, &window, &QWindow::close);
+ QTimer::singleShot(200, &app, []{ QCoreApplication::exit(0); });
+ app.exec();
+ QCOMPARE(quitSpy.quits, 0);
+ }
+
+ {
+ // Disabling quitOnLastWindowClosed automatic quit should not affect
+ // quitting when last QEventLoopLocker goes out of scope if
+ // there are no windows.
+ app.setQuitLockEnabled(true);
+ app.setQuitOnLastWindowClosed(false);
+
+ QuitSpy quitSpy;
+ QScopedPointer<QEventLoopLocker> locker(new QEventLoopLocker);
+ QTimer::singleShot(0, [&]{ locker.reset(nullptr); });
+ QTimer::singleShot(200, &app, []{ QCoreApplication::exit(0); });
+ app.exec();
+ QCOMPARE(quitSpy.quits, 1);
+ }
+
+ {
+ // Disabling quitOnLastWindowClosed automatic quit should still block
+ // quitting via QEventLoopLocker if there's a window alive.
app.setQuitLockEnabled(true);
app.setQuitOnLastWindowClosed(false);
@@ -1032,7 +1064,7 @@ void tst_QGuiApplication::quitOnLastWindowClosedWithEventLoopLocker()
QTimer::singleShot(0, [&]{ locker.reset(nullptr); });
QTimer::singleShot(200, &app, []{ QCoreApplication::exit(0); });
app.exec();
- QCOMPARE(quitSpy.quits, 1);
+ QCOMPARE(quitSpy.quits, 0);
}
{