summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qcoreapplication.cpp
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-10-12 16:33:00 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-10-18 15:29:09 +0200
commitdf359bcb703db5a8adbf14e88ba4ae0d54f0cfcd (patch)
tree54c71f280fa4b5056f6ae3ad7f0aa61cabfcd82e /src/corelib/kernel/qcoreapplication.cpp
parent55f8f916ce18047cb38e3512c7c5c87f7eb991d4 (diff)
Decouple quitOnLastWindowClosed from quitLockEnabled
In a512e210ac5b032c5fc2edf1ddf72e5a414485fda512e21 quitOnLastWindowClosed was changed to be implemented in terms of quitLockEnabled, but without any documentation to that end. Although the two features are similar (automatic quit under certain conditions), and interact, it doesn't make sense to overlap them until we actually expose them as a single property (automaticQuit e.g.) The logic for determining whether we can can quit automatically has been refactored to take both properties into account, on both a Core and Gui level. The call sites still need to check the individual properties to determine whether to activate automatic quit for that particular code path. Change-Id: I38c3e8cb30db373ea73dd45f150e5048c0db2f4d Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/corelib/kernel/qcoreapplication.cpp')
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp36
1 files changed, 28 insertions, 8 deletions
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
index 727fc825e0..c980e70dbf 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -400,7 +400,7 @@ struct QCoreApplicationData {
Q_GLOBAL_STATIC(QCoreApplicationData, coreappdata)
#ifndef QT_NO_QOBJECT
-static bool quitLockRefEnabled = true;
+static bool quitLockEnabled = true;
#endif
#if defined(Q_OS_WIN)
@@ -1020,14 +1020,14 @@ bool QCoreApplication::testAttribute(Qt::ApplicationAttribute attribute)
bool QCoreApplication::isQuitLockEnabled()
{
- return quitLockRefEnabled;
+ return quitLockEnabled;
}
static bool doNotify(QObject *, QEvent *);
void QCoreApplication::setQuitLockEnabled(bool enabled)
{
- quitLockRefEnabled = enabled;
+ quitLockEnabled = enabled;
}
/*!
@@ -1982,14 +1982,34 @@ void QCoreApplicationPrivate::ref()
void QCoreApplicationPrivate::deref()
{
- if (!quitLockRef.deref())
- maybeQuit();
+ quitLockRef.deref();
+
+ if (quitLockEnabled && canQuitAutomatically())
+ quitAutomatically();
}
-void QCoreApplicationPrivate::maybeQuit()
+bool QCoreApplicationPrivate::canQuitAutomatically()
{
- if (quitLockRef.loadRelaxed() == 0 && in_exec && quitLockRefEnabled && shouldQuit())
- QCoreApplication::postEvent(QCoreApplication::instance(), new QEvent(QEvent::Quit));
+ if (!in_exec)
+ return false;
+
+ if (quitLockEnabled && quitLockRef.loadRelaxed())
+ return false;
+
+ return true;
+}
+
+void QCoreApplicationPrivate::quitAutomatically()
+{
+ Q_Q(QCoreApplication);
+
+ // Explicit requests by the user to quit() is plumbed via the platform
+ // if possible, and delivers the quit event synchronously. For automatic
+ // quits we implicitly support cancelling the quit by showing another
+ // window, which currently relies on removing any posted quit events
+ // from the event queue. As a result, we can't use the normal quit()
+ // code path, and need to post manually.
+ QCoreApplication::postEvent(q, new QEvent(QEvent::Quit));
}
/*!