From fc9853dcbf546c82a46cd526c04b80d4e59e99f0 Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Thu, 6 Apr 2023 12:22:28 +0200 Subject: [PATCH] QMainWindow: fix potential crash when restoring tab bar state Don't activate the mainwindow layout while it is being restored. Otherwise we might end up in recursive calls to setGeometry. Pick-to: 6.5 Fixes: QTBUG-111538 Change-Id: I4b6cba9e0abfbae479f71a65b1c4526d92dac081 Reviewed-by: Volker Hilsheimer --- src/widgets/widgets/qmainwindowlayout.cpp | 5 ++++- src/widgets/widgets/qmainwindowlayout_p.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp index a1b1b20869..6fb263f87d 100644 --- a/src/widgets/widgets/qmainwindowlayout.cpp +++ b/src/widgets/widgets/qmainwindowlayout.cpp @@ -46,6 +46,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE using namespace Qt::StringLiterals; @@ -1813,7 +1815,7 @@ bool QMainWindowTabBar::event(QEvent *e) QTabBar *QMainWindowLayout::getTabBar() { - if (!usedTabBars.isEmpty()) { + if (!usedTabBars.isEmpty() && !isInRestoreState) { /* If dock widgets have been removed and added while the main window was hidden, then the layout hasn't been activated yet, and tab bars from empty @@ -2960,6 +2962,7 @@ void QMainWindowLayout::saveState(QDataStream &stream) const bool QMainWindowLayout::restoreState(QDataStream &stream) { + QScopedValueRollback guard(isInRestoreState, true); savedState = layoutState; layoutState.clear(); layoutState.rect = savedState.rect; diff --git a/src/widgets/widgets/qmainwindowlayout_p.h b/src/widgets/widgets/qmainwindowlayout_p.h index 394a052a09..0f784b56d0 100644 --- a/src/widgets/widgets/qmainwindowlayout_p.h +++ b/src/widgets/widgets/qmainwindowlayout_p.h @@ -586,6 +586,7 @@ private: #if QT_CONFIG(tabbar) void updateTabBarShapes(); #endif + bool isInRestoreState = false; }; #if QT_CONFIG(dockwidget) && !defined(QT_NO_DEBUG_STREAM)