From a512e210ac5b032c5fc2edf1ddf72e5a414485fd Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 26 Oct 2011 13:29:51 +0200 Subject: 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 Reviewed-by: Bradley T. Hughes --- src/gui/kernel/qwindow.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/gui/kernel/qwindow.cpp') diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index e85d8379fa..4436884359 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -165,6 +165,14 @@ void QWindow::setVisible(bool visible) return; d->visible = visible; emit visibleChanged(visible); + if (QCoreApplication::instance() && !transientParent()) { + QCoreApplicationPrivate *applicationPrivate = static_cast(QObjectPrivate::get(QCoreApplication::instance())); + if (visible) { + applicationPrivate->ref(); + } else { + applicationPrivate->deref(); + } + } if (!d->platformWindow) create(); @@ -499,7 +507,19 @@ void QWindow::setWindowState(Qt::WindowState state) void QWindow::setTransientParent(QWindow *parent) { Q_D(QWindow); + + QWindow *previousParent = d->transientParent; + d->transientParent = parent; + + if (QCoreApplication::instance() && d->visible) { + QCoreApplicationPrivate *applicationPrivate = static_cast(QObjectPrivate::get(QCoreApplication::instance())); + if (parent && !previousParent) { + applicationPrivate->deref(); + } else if (!parent && previousParent) { + applicationPrivate->ref(); + } + } } QWindow *QWindow::transientParent() const -- cgit v1.2.3