From 53bcd926e1ad7b229cc86df39eb73ac14fb53494 Mon Sep 17 00:00:00 2001 From: Marcus Venturi Date: Tue, 16 Dec 2025 07:25:33 +0100 Subject: [PATCH] Fix 2 crashes in singleShot timers while undocking tabs (especially in auto hide mode) --- src/DockAreaTabBar.cpp | 11 +++++++++-- src/DockContainerWidget.cpp | 10 ++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/DockAreaTabBar.cpp b/src/DockAreaTabBar.cpp index 8de254c40..acd0a2c16 100644 --- a/src/DockAreaTabBar.cpp +++ b/src/DockAreaTabBar.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include "FloatingDockContainer.h" #include "DockAreaWidget.h" @@ -111,9 +112,15 @@ void DockAreaTabBarPrivate::updateTabs() // Sometimes the synchronous calculation of the rectangular area fails // Therefore we use QTimer::singleShot here to execute the call // within the event loop - see #520 - QTimer::singleShot(0, _this, [&, TabWidget] + QPointer __this = _this; + QPointer __tabWidget = TabWidget; + + QTimer::singleShot(0, TabWidget, [__this, __tabWidget] { - _this->ensureWidgetVisible(TabWidget); + if (__this && __tabWidget) + { + __this->ensureWidgetVisible(__tabWidget); + } }); } else diff --git a/src/DockContainerWidget.cpp b/src/DockContainerWidget.cpp index 0a4deafc2..eb8217e2b 100644 --- a/src/DockContainerWidget.cpp +++ b/src/DockContainerWidget.cpp @@ -151,7 +151,7 @@ class DockContainerWidgetPrivate int VisibleDockAreaCount = -1; CDockAreaWidget* TopLevelDockArea = nullptr; QTimer DelayedAutoHideTimer; - CAutoHideTab* DelayedAutoHideTab; + QPointer DelayedAutoHideTab; bool DelayedAutoHideShow = false; /** @@ -396,10 +396,12 @@ DockContainerWidgetPrivate::DockContainerWidgetPrivate(CDockContainerWidget* _pu std::fill(std::begin(LastAddedAreaCache),std::end(LastAddedAreaCache), nullptr); DelayedAutoHideTimer.setSingleShot(true); DelayedAutoHideTimer.setInterval(500); - QObject::connect(&DelayedAutoHideTimer, &QTimer::timeout, [this](){ - auto GlobalPos = DelayedAutoHideTab->mapToGlobal(QPoint(0, 0)); - qApp->sendEvent(DelayedAutoHideTab, new QMouseEvent(QEvent::MouseButtonPress, + QObject::connect(&DelayedAutoHideTimer, &QTimer::timeout, [this](){ + if (DelayedAutoHideTab) { + auto GlobalPos = DelayedAutoHideTab->mapToGlobal(QPoint(0, 0)); + qApp->sendEvent(DelayedAutoHideTab, new QMouseEvent(QEvent::MouseButtonPress, QPoint(0, 0), GlobalPos, Qt::LeftButton, {Qt::LeftButton}, Qt::NoModifier)); + } }); }