QMainWindowLayout: Fix leaking of unused tab bars

QMainWindowLayout::unusedTabBars contains unparented tab bars.
They are leaked when QMainWindow and its layout get destroyed.
They still are in QApplication::allWidgets(), which attempts to delete
them eventually. When that happens, they try to remove themselves from
an already deleted QMainWindowLayout::unusedTabBars.

Delete all unused tab bars in the d'tor of QMainWindowLayout.

Task-number: QTBUG-135468
Pick-to: 6.8 6.5
Change-Id: I5ac7748ef738955522567db585e9505e3ba435ad
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 23357e59bb4dc54e76a237b290aa64a620db2ea1)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Axel Spoerl 2025-04-02 15:41:21 +02:00 committed by Qt Cherry-pick Bot
parent 19c4db4201
commit ab6f1ad778

View File

@ -2726,6 +2726,11 @@ QMainWindowLayout::~QMainWindowLayout()
layoutState.deleteCentralWidgetItem();
delete statusbar;
// unusedTabBars contains unparented tab bars, which need to be removed manually.
// ~QMainWindowTabBar() removes the bar from unusedTabBars => call qDeleteAll() on a copy.
const auto bars = unusedTabBars;
qDeleteAll(bars);
}
void QMainWindowLayout::setDockOptions(QMainWindow::DockOptions opts)