From a110d53a53938ca43910d426f91d5a98644ead63 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Thu, 18 Nov 2021 22:10:11 +0100 Subject: [PATCH] Fixed crash in DockFocusController DockWidget pointers are now wrapped into QPointer to detect deleted DockWidgets --- src/DockFocusController.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/DockFocusController.cpp b/src/DockFocusController.cpp index f958111..595c9fa 100644 --- a/src/DockFocusController.cpp +++ b/src/DockFocusController.cpp @@ -32,6 +32,8 @@ namespace ads { +static const char* const FocusedDockWidgetProperty = "FocusedDockWidget"; + /** * Private data class of CDockFocusController class (pimpl) */ @@ -57,8 +59,8 @@ struct DockFocusControllerPrivate * the dock area that it belongs to */ void updateDockWidgetFocus(CDockWidget* DockWidget); -}; -// struct DockFocusControllerPrivate +}; // struct DockFocusControllerPrivate + //=========================================================================== @@ -125,7 +127,7 @@ void DockFocusControllerPrivate::updateDockWidgetFocus(CDockWidget* DockWidget) if (Window) { - Window->setProperty("FocusedDockWidget", QVariant::fromValue(DockWidget)); + Window->setProperty(FocusedDockWidgetProperty, QVariant::fromValue(QPointer(DockWidget))); } CDockAreaWidget* NewFocusedDockArea = nullptr; if (FocusedDockWidget) @@ -161,7 +163,7 @@ void DockFocusControllerPrivate::updateDockWidgetFocus(CDockWidget* DockWidget) if (NewFloatingWidget) { - NewFloatingWidget->setProperty("FocusedDockWidget", QVariant::fromValue(DockWidget)); + NewFloatingWidget->setProperty(FocusedDockWidgetProperty, QVariant::fromValue(QPointer(DockWidget))); } @@ -243,13 +245,13 @@ void CDockFocusController::onFocusWindowChanged(QWindow *focusWindow) return; } - auto vDockWidget = focusWindow->property("FocusedDockWidget"); + auto vDockWidget = focusWindow->property(FocusedDockWidgetProperty); if (!vDockWidget.isValid()) { return; } - auto DockWidget = vDockWidget.value(); + auto DockWidget = vDockWidget.value>(); if (!DockWidget) { return; @@ -376,13 +378,13 @@ void CDockFocusController::notifyFloatingWidgetDrop(CFloatingDockContainer* Floa return; } - auto vDockWidget = FloatingWidget->property("FocusedDockWidget"); + auto vDockWidget = FloatingWidget->property(FocusedDockWidgetProperty); if (!vDockWidget.isValid()) { return; } - auto DockWidget = vDockWidget.value(); + auto DockWidget = vDockWidget.value>(); if (DockWidget) { DockWidget->dockAreaWidget()->setCurrentDockWidget(DockWidget);