diff options
author | Gunnar Sletta <gunnar.sletta@digia.com> | 2013-11-15 11:26:38 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-20 14:10:37 +0100 |
commit | 54b8c27e03d04c1e5cd35f75d5c0a8111240eb74 (patch) | |
tree | bf109431cd3001c117f93f1027dd8e3a97a8aa34 /src/widgets/kernel/qwindowcontainer.cpp | |
parent | 16ad93af4959b3c0ae96a4a0d88e25c1626f587d (diff) |
Fix crash when windowcontainer is used in a dockwidget
The dockwidget's toplevel window would be a parent of the container's
window when floating. When plugged back into the mainwindow the
dockwidget's window is destroyed and the container's window along
with it. Added a function toplevelAboutToBeDestroyed to unparent
the containers window before this happens so parentWasChanged will
work correctly.
Change-Id: I06679cfb3a8fa3834c0db0be5973c012b8277275
Reviewed-by: Ulf Hermann <ulf.hermann@digia.com>
Reviewed-by: Jørgen Lind <jorgen.lind@digia.com>
Diffstat (limited to 'src/widgets/kernel/qwindowcontainer.cpp')
-rw-r--r-- | src/widgets/kernel/qwindowcontainer.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/widgets/kernel/qwindowcontainer.cpp b/src/widgets/kernel/qwindowcontainer.cpp index 6914f64f8e..7c319c5095 100644 --- a/src/widgets/kernel/qwindowcontainer.cpp +++ b/src/widgets/kernel/qwindowcontainer.cpp @@ -300,15 +300,28 @@ static void qwindowcontainer_traverse(QWidget *parent, qwindowcontainer_traverse } } +void QWindowContainer::toplevelAboutToBeDestroyed(QWidget *parent) +{ + if (QWindowContainerPrivate *d = QWindowContainerPrivate::get(parent)) { + d->window->setParent(&d->fakeParent); + } + qwindowcontainer_traverse(parent, toplevelAboutToBeDestroyed); +} + void QWindowContainer::parentWasChanged(QWidget *parent) { if (QWindowContainerPrivate *d = QWindowContainerPrivate::get(parent)) { if (d->window->parent()) { d->updateUsesNativeWidgets(); d->markParentChain(); - d->window->setParent(d->usesNativeWidgets - ? parent->windowHandle() - : parent->window()->windowHandle()); + QWidget *toplevel = d->usesNativeWidgets ? parent : parent->window(); + if (!toplevel->windowHandle()) { + QWidgetPrivate *tld = static_cast<QWidgetPrivate *>(QWidgetPrivate::get(toplevel)); + tld->createTLExtra(); + tld->createTLSysExtra(); + Q_ASSERT(toplevel->windowHandle()); + } + d->window->setParent(toplevel->windowHandle()); d->updateGeometry(); } } |