Skip to content

Commit 53bcd92

Browse files
author
Marcus Venturi
committed
Fix 2 crashes in singleShot timers while undocking tabs (especially in auto hide mode)
1 parent a674eea commit 53bcd92

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

src/DockAreaTabBar.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <QApplication>
3838
#include <QtGlobal>
3939
#include <QTimer>
40+
#include <QPointer>
4041

4142
#include "FloatingDockContainer.h"
4243
#include "DockAreaWidget.h"
@@ -111,9 +112,15 @@ void DockAreaTabBarPrivate::updateTabs()
111112
// Sometimes the synchronous calculation of the rectangular area fails
112113
// Therefore we use QTimer::singleShot here to execute the call
113114
// within the event loop - see #520
114-
QTimer::singleShot(0, _this, [&, TabWidget]
115+
QPointer<CDockAreaTabBar> __this = _this;
116+
QPointer<CDockWidgetTab> __tabWidget = TabWidget;
117+
118+
QTimer::singleShot(0, TabWidget, [__this, __tabWidget]
115119
{
116-
_this->ensureWidgetVisible(TabWidget);
120+
if (__this && __tabWidget)
121+
{
122+
__this->ensureWidgetVisible(__tabWidget);
123+
}
117124
});
118125
}
119126
else

src/DockContainerWidget.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class DockContainerWidgetPrivate
151151
int VisibleDockAreaCount = -1;
152152
CDockAreaWidget* TopLevelDockArea = nullptr;
153153
QTimer DelayedAutoHideTimer;
154-
CAutoHideTab* DelayedAutoHideTab;
154+
QPointer<CAutoHideTab> DelayedAutoHideTab;
155155
bool DelayedAutoHideShow = false;
156156

157157
/**
@@ -396,10 +396,12 @@ DockContainerWidgetPrivate::DockContainerWidgetPrivate(CDockContainerWidget* _pu
396396
std::fill(std::begin(LastAddedAreaCache),std::end(LastAddedAreaCache), nullptr);
397397
DelayedAutoHideTimer.setSingleShot(true);
398398
DelayedAutoHideTimer.setInterval(500);
399-
QObject::connect(&DelayedAutoHideTimer, &QTimer::timeout, [this](){
400-
auto GlobalPos = DelayedAutoHideTab->mapToGlobal(QPoint(0, 0));
401-
qApp->sendEvent(DelayedAutoHideTab, new QMouseEvent(QEvent::MouseButtonPress,
399+
QObject::connect(&DelayedAutoHideTimer, &QTimer::timeout, [this](){
400+
if (DelayedAutoHideTab) {
401+
auto GlobalPos = DelayedAutoHideTab->mapToGlobal(QPoint(0, 0));
402+
qApp->sendEvent(DelayedAutoHideTab, new QMouseEvent(QEvent::MouseButtonPress,
402403
QPoint(0, 0), GlobalPos, Qt::LeftButton, {Qt::LeftButton}, Qt::NoModifier));
404+
}
403405
});
404406
}
405407

0 commit comments

Comments
 (0)