summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qapplication.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2014-02-11 13:00:59 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-14 00:34:25 +0100
commit9835a63dde06a1e5d2f0452d50da86aa6790e4f7 (patch)
tree877a77c94daf2844c04e140376b0ef415cd35ae7 /src/widgets/kernel/qapplication.cpp
parentff11af4fbc2948a3a3bc635549c7ac349d249abc (diff)
Close widgets properly from session management.
Introduce new virtual QGuiApplicationPrivate::tryCloseAllWindows() which allows overriding the behavior in QApplication to properly close the widgets first. Without this, QGuiApplication closes the widget windows leaving a stale window handle behind in the associated QWidget which then causes the application not to terminate since QApplication::shouldQuit() stills finds the affected widgets to be visible. Task-number: QTBUG-35986 Change-Id: I19ac4b5a19250ee68d09e461c03dbace458c98e4 Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/widgets/kernel/qapplication.cpp')
-rw-r--r--src/widgets/kernel/qapplication.cpp55
1 files changed, 37 insertions, 18 deletions
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index 513d98867c..3309b4be06 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -1733,6 +1733,41 @@ QFontMetrics QApplication::fontMetrics()
return desktop()->fontMetrics();
}
+bool QApplicationPrivate::tryCloseAllWidgetWindows(QWindowList *processedWindows)
+{
+ Q_ASSERT(processedWindows);
+ while (QWidget *w = QApplication::activeModalWidget()) {
+ if (!w->isVisible() || w->data->is_closing)
+ break;
+ QWindow *window = w->windowHandle();
+ if (!w->close()) // Qt::WA_DeleteOnClose may cause deletion.
+ return false;
+ if (window)
+ processedWindows->append(window);
+ }
+
+ QWidgetList list = QApplication::topLevelWidgets();
+ for (int i = 0; i < list.size(); ++i) {
+ QWidget *w = list.at(i);
+ if (w->isVisible() && w->windowType() != Qt::Desktop && !w->data->is_closing) {
+ QWindow *window = w->windowHandle();
+ if (!w->close()) // Qt::WA_DeleteOnClose may cause deletion.
+ return false;
+ if (window)
+ processedWindows->append(window);
+ list = QApplication::topLevelWidgets();
+ i = -1;
+ }
+ }
+ return true;
+}
+
+bool QApplicationPrivate::tryCloseAllWindows()
+{
+ QWindowList processedWindows;
+ return QApplicationPrivate::tryCloseAllWidgetWindows(&processedWindows)
+ && QGuiApplicationPrivate::tryCloseRemainingWindows(processedWindows);
+}
/*!
Closes all top-level windows.
@@ -1754,24 +1789,8 @@ QFontMetrics QApplication::fontMetrics()
*/
void QApplication::closeAllWindows()
{
- bool did_close = true;
- QWidget *w;
- while ((w = activeModalWidget()) && did_close) {
- if (!w->isVisible() || w->data->is_closing)
- break;
- did_close = w->close();
- }
- QWidgetList list = QApplication::topLevelWidgets();
- for (int i = 0; did_close && i < list.size(); ++i) {
- w = list.at(i);
- if (w->isVisible()
- && w->windowType() != Qt::Desktop
- && !w->data->is_closing) {
- did_close = w->close();
- list = QApplication::topLevelWidgets();
- i = -1;
- }
- }
+ QWindowList processedWindows;
+ QApplicationPrivate::tryCloseAllWidgetWindows(&processedWindows);
}
/*!