From ad0c2103bf36a289a07aa9f9977f5f7b525ff70f Mon Sep 17 00:00:00 2001 From: Syarif Fakhri Date: Fri, 14 Oct 2022 16:09:13 +0800 Subject: [PATCH] fix crash when using widgets that delete on close --- src/AutoHideDockContainer.cpp | 8 +++----- src/DockContainerWidget.cpp | 8 +++++++- src/DockWidget.cpp | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/AutoHideDockContainer.cpp b/src/AutoHideDockContainer.cpp index 65bb075..83a34fe 100644 --- a/src/AutoHideDockContainer.cpp +++ b/src/AutoHideDockContainer.cpp @@ -196,9 +196,6 @@ CAutoHideDockContainer::CAutoHideDockContainer(CDockManager* DockManager, CDockW updateSize(); parent->registerAutoHideWidget(this); - - d->DockArea->installEventFilter(this); - parent->installEventFilter(this); } //============================================================================ @@ -231,8 +228,7 @@ CAutoHideDockContainer::~CAutoHideDockContainer() ADS_PRINT("~CAutoHideDockContainer"); // Remove event filter in case there are any queued messages - d->DockArea->removeEventFilter(this); - parent()->removeEventFilter(this); + qApp->removeEventFilter(this); if (d->DockManager) { @@ -439,6 +435,8 @@ void CAutoHideDockContainer::collapseView(bool Enable) show(); d->DockArea->show(); d->DockWidget->show(); + updateMask(); + updateSize(); qApp->installEventFilter(this); } } diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index fa928e1..eccfec8 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -1054,9 +1054,10 @@ bool DockContainerWidgetPrivate::restoreAutoHideDockArea(CDockingStateReader& s, } CDockAreaWidget* DockArea = nullptr; + CAutoHideDockContainer* dockContainer = nullptr; if (!Testing) { - const auto dockContainer = new CAutoHideDockContainer(DockManager, area, _this); + dockContainer = new CAutoHideDockContainer(DockManager, area, _this); if (!dockContainer->restoreState(s, Testing)) { return false; @@ -1108,6 +1109,11 @@ bool DockContainerWidgetPrivate::restoreAutoHideDockArea(CDockingStateReader& s, DockArea->autoHideDockContainer()->toggleView(!Closed); } + if (dockContainer && !dockContainer->dockWidget()) + { + dockContainer->cleanupAndDelete(); + } + return true; } diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index 2a90d3d..0d189a0 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -248,7 +248,7 @@ void DockWidgetPrivate::updateParentDockArea() void DockWidgetPrivate::closeAutoHideDockWidgetsIfNeeded() { - if (_this->dockContainer() && _this->dockContainer()->openedDockWidgets().isEmpty()) + if (_this->dockContainer() && _this->dockContainer()->openedDockWidgets().isEmpty() && !_this->dockManager()->isRestoringState()) { for (auto autoHideWidget : _this->dockContainer()->autoHideWidgets()) {