diff options
author | Stephen Kelly <stephen.kelly@kdab.com> | 2011-10-26 13:29:51 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-31 23:22:15 +0100 |
commit | a512e210ac5b032c5fc2edf1ddf72e5a414485fd (patch) | |
tree | 0e9615f317fe5c24bd002155b205a01d5716a1d3 /src/corelib/kernel/qcoreapplication.cpp | |
parent | 36a590c90ddab6fa438b7b54b05d89e8f9698a52 (diff) |
Add the event loop quitlock feature to QtCore.
A feature of a ref-counted quit (managed by a quit-lock class)
is added to both QEventLoop and QCoreApplication.
This allows, for example, an event loop to quit() when there is
no more work for it to do.
quitOnLastWindowClosed is implemented in terms of the refcount in
QCoreApplication so that jobs can be completed before the
application quits.
Change-Id: I14c8f4e7ee12bbf81a6e5849290d4c8ff37fa110
Reviewed-by: David Faure <faure@kde.org>
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
Diffstat (limited to 'src/corelib/kernel/qcoreapplication.cpp')
-rw-r--r-- | src/corelib/kernel/qcoreapplication.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index ae30167a42..a248e18a6a 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -271,6 +271,8 @@ struct QCoreApplicationData { Q_GLOBAL_STATIC(QCoreApplicationData, coreappdata) +static bool quitLockRefEnabled = true; + QCoreApplicationPrivate::QCoreApplicationPrivate(int &aargc, char **aargv, uint flags) : QObjectPrivate(), argc(aargc), argv(aargv), application_type(0), eventFilter(0), in_exec(false), aboutToQuitEmitted(false), threadData_clean(false) @@ -649,6 +651,29 @@ bool QCoreApplication::testAttribute(Qt::ApplicationAttribute attribute) return QCoreApplicationPrivate::testAttribute(attribute); } +/*!/ + Returns true if the use of the QEventLoopLocker feature can cause the + application to quit, otherwise returns false. + + \sa QEventLoopLocker + */ +bool QCoreApplication::isQuitLockEnabled() +{ + return quitLockRefEnabled; +} + +/*! + Enables the ability of the QEventLoopLocker feature to quit + the application. + + If disabled, the use of QEventLoopLocker will not quit the application. + + \sa QEventLoopLocker + */ +void QCoreApplication::setQuitLockEnabled(bool enabled) +{ + quitLockRefEnabled = enabled; +} /*! \internal @@ -1476,6 +1501,17 @@ bool QCoreApplication::event(QEvent *e) \sa QObject::tr(), QObject::trUtf8(), QString::fromUtf8() */ +void QCoreApplicationPrivate::ref() +{ + quitLockRef.ref(); +} + +void QCoreApplicationPrivate::deref() +{ + if (!quitLockRef.deref() && in_exec && quitLockRefEnabled) + QCoreApplication::postEvent(qApp, new QEvent(QEvent::Quit)); +} + /*! Tells the application to exit with return code 0 (success). Equivalent to calling QCoreApplication::exit(0). |