blob: ee872fb6b04b76fdf10b8fdd5784bfda770e8add (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
From 5afd51aaf7e92953504748583c7573fca2bccce5 Mon Sep 17 00:00:00 2001
From: Axel Spoerl <axel.spoerl@qt.io>
Date: Tue, 17 Jun 2025 14:10:24 +0200
Subject: [PATCH 29/31] Centralise usage of unused tab bars in
QMainWindowLayout
Unused tab bars can cause crashes in the QMainWindow d'tor.
Centralise handling of unused tab bars to avoid access to the container
at multiple places.
This patch doesn't change functionality.
Task-number: QTBUG-137755
Change-Id: I70445c1efbbbff3ed637e1c3a531aa90b6584c9e
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
(cherry picked from commit a3f0ce4c0d0627ef979052b34b21e6fd2bdc3acf)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 3fd873079e2fe8ffad0595015230a82c765e27c1)
---
src/widgets/widgets/qmainwindowlayout.cpp | 24 ++++++++++++++++++-----
src/widgets/widgets/qmainwindowlayout_p.h | 2 ++
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp
index dab473a900d..ce1bc208b43 100644
--- a/src/widgets/widgets/qmainwindowlayout.cpp
+++ b/src/widgets/widgets/qmainwindowlayout.cpp
@@ -2048,7 +2048,7 @@ QMainWindowTabBar::~QMainWindowTabBar()
auto *mwLayout = qt_mainwindow_layout(mainWindow);
if (!mwLayout)
return;
- mwLayout->unusedTabBars.removeOne(this);
+ mwLayout->purgeTabBar(this);
mwLayout->usedTabBars.remove(this);
}
@@ -2104,6 +2104,23 @@ bool QMainWindowLayout::isDockWidgetTabbed(const QDockWidget *dockWidget) const
return bar && bar->count() > 1;
}
+void QMainWindowLayout::purgeTabBar(QTabBar *bar)
+{
+ Q_ASSERT(qobject_cast<QMainWindowTabBar *>(bar));
+ bar->hide();
+ while (bar->count() > 0)
+ bar->removeTab(0);
+ unusedTabBars.removeOne(bar);
+}
+
+void QMainWindowLayout::unuseTabBar(QTabBar *bar)
+{
+ Q_ASSERT(qobject_cast<QMainWindowTabBar *>(bar));
+ Q_ASSERT(!unusedTabBars.contains(bar));
+ unusedTabBars.append(bar);
+ usedTabBars.remove(bar);
+}
+
QTabBar *QMainWindowLayout::getTabBar()
{
if (!usedTabBars.isEmpty() && !isInRestoreState) {
@@ -3212,10 +3229,7 @@ void QMainWindowLayout::applyState(QMainWindowLayoutState &newState, bool animat
const QSet<QTabBar*> retired = usedTabBars - used;
usedTabBars = used;
for (QTabBar *tab_bar : retired) {
- tab_bar->hide();
- while (tab_bar->count() > 0)
- tab_bar->removeTab(0);
- unusedTabBars.append(tab_bar);
+ unuseTabBar(tab_bar);
}
if (sep == 1) {
diff --git a/src/widgets/widgets/qmainwindowlayout_p.h b/src/widgets/widgets/qmainwindowlayout_p.h
index 3cc62c7d917..3f59f7d4524 100644
--- a/src/widgets/widgets/qmainwindowlayout_p.h
+++ b/src/widgets/widgets/qmainwindowlayout_p.h
@@ -550,6 +550,8 @@ public:
void setDocumentMode(bool enabled);
QTabBar *getTabBar();
+ void unuseTabBar(QTabBar *bar);
+ void purgeTabBar(QTabBar *bar);
QSet<QTabBar*> usedTabBars;
QList<QTabBar*> unusedTabBars;
bool verticalTabsEnabled;
--
2.50.1
|