From 66603985f2de74ac5f3bd5d259f0e65f710f62d7 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 11 Feb 2012 01:33:55 +0100 Subject: Fix ref counted window close handling. Instead of refcounting QWindow visibility, we ask the Application subclass whether quitting is appropriate. Task-Id: QTBUG-24120 Change-Id: Idd19cc1a3e5742fddded89c7638aaaa5e47c568d Reviewed-by: Bradley T. Hughes Reviewed-by: Robin Burchell --- src/widgets/kernel/qapplication.cpp | 15 +++++++++++++++ src/widgets/kernel/qapplication_p.h | 2 ++ src/widgets/kernel/qwidget.cpp | 20 ++++++++++++++++++-- 3 files changed, 35 insertions(+), 2 deletions(-) (limited to 'src/widgets/kernel') diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 4387d2a287..b04925d85d 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -67,6 +67,7 @@ #include "private/qstylesheetstyle_p.h" #include "private/qstyle_p.h" #include "qmessagebox.h" +#include "qwidgetwindow_qpa_p.h" #include #include #include @@ -3289,6 +3290,20 @@ int QApplication::exec() return QGuiApplication::exec(); } +bool QApplicationPrivate::shouldQuit() +{ + /* if there is no non-withdrawn primary window left (except + the ones without QuitOnClose), we emit the lastWindowClosed + signal */ + QWidgetList list = QApplication::topLevelWidgets(); + for (int i = 0; i < list.size(); ++i) { + QWidget *w = list.at(i); + if (w->isVisible() && !w->parentWidget() && w->testAttribute(Qt::WA_QuitOnClose)) + return false; + } + return true; +} + /*! \reimp */ bool QApplication::notify(QObject *receiver, QEvent *e) diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h index 790176afe3..e728868182 100644 --- a/src/widgets/kernel/qapplication_p.h +++ b/src/widgets/kernel/qapplication_p.h @@ -178,6 +178,8 @@ public: virtual void notifyLayoutDirectionChange(); virtual void notifyActiveWindowChange(QWindow *); + virtual bool shouldQuit(); + #if defined(Q_WS_X11) #ifndef QT_NO_SETTINGS static bool x11_apply_settings(); diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index f98f7fbe66..f095e475af 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -7410,8 +7410,24 @@ bool QWidgetPrivate::close_helper(CloseMode mode) // Attempt to close the application only if this has WA_QuitOnClose set and a non-visible parent quitOnClose = quitOnClose && (parentWidget.isNull() || !parentWidget->isVisible()); - if (quitOnClose && q->windowHandle()) { - static_cast(QObjectPrivate::get(q->windowHandle()))->maybeQuitOnLastWindowClosed(); + if (quitOnClose) { + /* if there is no non-withdrawn primary window left (except + the ones without QuitOnClose), we emit the lastWindowClosed + signal */ + QWidgetList list = QApplication::topLevelWidgets(); + bool lastWindowClosed = true; + for (int i = 0; i < list.size(); ++i) { + QWidget *w = list.at(i); + if (!w->isVisible() || w->parentWidget() || !w->testAttribute(Qt::WA_QuitOnClose)) + continue; + lastWindowClosed = false; + break; + } + if (lastWindowClosed) { + QGuiApplicationPrivate::emitLastWindowClosed(); + QCoreApplicationPrivate *applicationPrivate = static_cast(QObjectPrivate::get(QCoreApplication::instance())); + applicationPrivate->maybeQuit(); + } } -- cgit v1.2.3