QMainWindowTabBar: Add destructor

QMainWindowLayout re-uses tab bars. A QSet and a QList member are kept,
to track used and unused tab bars.

Corner cases upon application close down leave dangling pointers in
those containers.

=> Add a destructor to QMainWindowTabBar
=> remove the tab bar from used and unused tab bar containers, if
not directly parented to the main window.

=> No longer reparent unused tab bars of a QDockWidgetGroupWindow
to the main window. Let them be destroyed as a group window child,
and its destructor remove it from the used/unused tab bar container.

Pick-to: 6.6 6.5
Change-Id: If2388cf878553dc89583dbc8585748fad65bbab2
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Axel Spoerl 2023-11-17 11:12:26 +01:00
parent 929b5a2273
commit b6b489db69

View File

@ -424,11 +424,6 @@ void QDockWidgetGroupWindow::destroyOrHideIfEmpty()
if (!wasHidden)
dw->show();
}
#if QT_CONFIG(tabbar)
const auto tabBars = findChildren<QTabBar *>(Qt::FindDirectChildrenOnly);
for (QTabBar *tb : tabBars)
tb->setParent(parentWidget());
#endif
deleteLater();
}
@ -1752,6 +1747,7 @@ class QMainWindowTabBar : public QTabBar
{
QMainWindow *mainWindow;
QPointer<QDockWidget> draggingDock; // Currently dragging (detached) dock widget
~QMainWindowTabBar();
public:
QMainWindowTabBar(QMainWindow *parent);
protected:
@ -1817,6 +1813,21 @@ void QMainWindowTabBar::mouseMoveEvent(QMouseEvent *e)
QTabBar::mouseMoveEvent(e);
}
QMainWindowTabBar::~QMainWindowTabBar()
{
if (!mainWindow || mainWindow == parentWidget())
return;
// tab bar is not parented to the main window
// => can only be a dock widget group window
// => remove itself from used and unused tab bar containers
auto *mwLayout = qt_mainwindow_layout(mainWindow);
if (!mwLayout)
return;
mwLayout->unusedTabBars.removeOne(this);
mwLayout->usedTabBars.remove(this);
}
void QMainWindowTabBar::mouseReleaseEvent(QMouseEvent *e)
{
if (draggingDock && e->button() == Qt::LeftButton) {