diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-10-12 15:25:26 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-10-16 14:33:28 +0200 |
commit | 1dfc74970c8ab0bfc210b7038aad401189eae542 (patch) | |
tree | a85b88588e11a181ae97ee2e3aedef4bd452f8c7 /src/gui/kernel/qwindow.cpp | |
parent | 30404b49d8cc9ad8c4d9f128952844c20da0ad0d (diff) |
Deduplicate lastWindowClosed handling
Whenever a window was closed, we had logic to check if it was the last
window, and if so emitted lastWindowClosed and then tried to quit the
application. But the automatic quit process also checked if there were
any remaining windows, as this process could be triggered as a result
of a QEventLoopLocker going out of scope. The two paths now share the
same logic for determining if there are any remaining windows.
The docs have been updated to reflect the original intent of the logic,
dealing only with primary windows (top levels without a transient parent).
This was how both the original code paths implemented their logic.
For historical reasons the Qt::WA_QuitOnClose attribute is closely
tied to the lastWindowClosed signal, and isn't merely limited to
controlling whether we try an automatic quit when the last window
closes. For now this behavior has been kept, but the docs have been
updated to clarify how the attribute is handled in practice.
Change-Id: If3d06b065236aad2e59e9091cac3146bc4cf79f6
Reviewed-by: Doris Verria <doris.verria@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/gui/kernel/qwindow.cpp')
-rw-r--r-- | src/gui/kernel/qwindow.cpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 275d190a5a..26ad97bc86 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -2269,16 +2269,25 @@ bool QWindow::close() return d->platformWindow->close(); } -bool QWindowPrivate::shouldTriggerQuitOnClose() const +bool QWindowPrivate::participatesInLastWindowClosed() const { Q_Q(const QWindow); - return q->isTopLevel(); -} -bool QWindowPrivate::shouldCancelQuitOnClose() const -{ - Q_Q(const QWindow); - return q->isVisible() && !q->transientParent() && q->type() != Qt::ToolTip; + if (!q->isTopLevel()) + return false; + + // Tool-tip widgets do not normally have Qt::WA_QuitOnClose, + // but since we do not have a similar flag for non-widget + // windows we need an explicit exclusion here as well. + if (q->type() == Qt::ToolTip) + return false; + + // A window with a transient parent is not a primary window, + // it's a secondary window. + if (q->transientParent()) + return false; + + return true; } /*! |