Skip to content

Commit

Permalink
Skip already closing widgets when checking whether application can quit
Browse files Browse the repository at this point in the history
QApplication tries to close all windows on quit using closeAllWindows,
but closeAllWindows skips windows that are already closing. This can
happen when calling quit() from a close event for example.

QApplication then tries to verify that all windows have been closed,
and that logic should skip the same kind of windows as closeAllWindows
does.

The fact that these two logics diverge was identified earlier in
5af73cd, but aligning them required further work. As that
commit notes, the right fix to align them is building on top of
tryCloseAllWidgetWindows(), which already returns true/false based on
whether it could close all windows or not. But, unlike the existing
logic in QApplication::event(), it doesn't skip Popups or Dialogs,
so that discrepancy needs further research.

Pick-to: 6.0
Fixes: QTBUG-89580
Change-Id: I87bff56f2eb8a539f1c859c957f5f239dc1eb93d
Reviewed-by: Andy Shaw <[email protected]>
Reviewed-by: Kai Koehne <[email protected]>
Reviewed-by: Volker Hilsheimer <[email protected]>
  • Loading branch information
torarnv committed Jan 6, 2021
1 parent c9a1102 commit e7370d0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/widgets/kernel/qapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1660,8 +1660,14 @@ bool QApplication::event(QEvent *e)
{
Q_D(QApplication);
if (e->type() == QEvent::Quit) {
// FIXME: This logic first tries to close all windows, and then
// checks whether it was successful, but the conditions used in
// closeAllWindows() differ from the verification logic below.
// We should build on the logic in tryCloseAllWidgetWindows().
closeAllWindows();
for (auto *w : topLevelWidgets()) {
if (w->data->is_closing)
continue;
if (w->isVisible() && !(w->windowType() == Qt::Desktop) && !(w->windowType() == Qt::Popup) &&
(!(w->windowType() == Qt::Dialog) || !w->parentWidget()) && !w->testAttribute(Qt::WA_DontShowOnScreen)) {
e->ignore();
Expand Down

0 comments on commit e7370d0

Please sign in to comment.