From 9c3a58a913a7e59359146264ee59d40d703d4db2 Mon Sep 17 00:00:00 2001 From: Dyami Caliri Date: Wed, 27 Aug 2014 09:27:50 -0700 Subject: Recreate child windows when changing screens When setting a new screen, the code calls QWindow::destroy(), which recursively destroys all child windows. It then calls create() on the top-level window, leaving child windows destroyed. This causes crashes if you have embedded native widgets. Task-number: QTBUG-40817 Change-Id: Iaace2589f48bbfd5faaf5ff95357ff43b310504a Reviewed-by: Shawn Rutledge Reviewed-by: Laszlo Agocs --- src/gui/kernel/qwindow.cpp | 34 +++++++++++++++++++++------------- src/gui/kernel/qwindow_p.h | 1 + 2 files changed, 22 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index d6f9fad070..6724d68c95 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -367,12 +367,31 @@ void QWindowPrivate::setScreen(QScreen *newScreen, bool recreate) if (newScreen) { q->connect(screen, SIGNAL(destroyed(QObject*)), q, SLOT(screenDestroyed(QObject*))); if (shouldRecreate) - q->create(); + create(true); } emit q->screenChanged(newScreen); } } +void QWindowPrivate::create(bool recursive) +{ + Q_Q(QWindow); + if (!platformWindow) { + platformWindow = QGuiApplicationPrivate::platformIntegration()->createPlatformWindow(q); + QObjectList childObjects = q->children(); + for (int i = 0; i < childObjects.size(); i ++) { + QObject *object = childObjects.at(i); + if (object->isWindowType()) { + QWindow *window = static_cast(object); + if (recursive) + window->d_func()->create(true); + if (window->d_func()->platformWindow) + window->d_func()->platformWindow->setParent(platformWindow); + } + } + } +} + void QWindowPrivate::clearFocusObject() { } @@ -490,18 +509,7 @@ bool QWindow::isVisible() const void QWindow::create() { Q_D(QWindow); - if (!d->platformWindow) { - d->platformWindow = QGuiApplicationPrivate::platformIntegration()->createPlatformWindow(this); - QObjectList childObjects = children(); - for (int i = 0; i < childObjects.size(); i ++) { - QObject *object = childObjects.at(i); - if(object->isWindowType()) { - QWindow *window = static_cast(object); - if (window->d_func()->platformWindow) - window->d_func()->platformWindow->setParent(d->platformWindow); - } - } - } + d->create(false); } /*! diff --git a/src/gui/kernel/qwindow_p.h b/src/gui/kernel/qwindow_p.h index 4305edea51..51d78bb9cd 100644 --- a/src/gui/kernel/qwindow_p.h +++ b/src/gui/kernel/qwindow_p.h @@ -132,6 +132,7 @@ public: void _q_clearAlert(); void setScreen(QScreen *newScreen, bool recreate); + void create(bool recursive); virtual void clearFocusObject(); -- cgit v1.2.3