From 70ad4042033219d9cafc66f7b6365aa0caeeee3e Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 21 Apr 2020 17:24:03 +0200 Subject: [PATCH] QMainWindow: don't grow memory when modifying tabbed docks while hidden QMainWindow tries to avoid memory allocations by caching tab bars that are no longer used. That cache is populated when the layout is activated. The layout might never be activated when the main window is never shown, in which case adding and removing dock widgets at runtime will continuously allocate more memory for tab bars that are created. A workaround is to call QMainWindow::layout()->activate() explicitly in application code, once all dock widgets have been removed. This change avoids that applications have to do that. Change-Id: I70eb585d2120f0b7b73f59c3ee65d7242c12ec59 Fixes: QTBUG-83135 Pick-to: 5.15 Reviewed-by: Richard Moe Gustavsen --- src/widgets/widgets/qmainwindowlayout.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp index 83697278b8..857ca31529 100644 --- a/src/widgets/widgets/qmainwindowlayout.cpp +++ b/src/widgets/widgets/qmainwindowlayout.cpp @@ -1779,6 +1779,15 @@ bool QMainWindowTabBar::event(QEvent *e) QTabBar *QMainWindowLayout::getTabBar() { + if (!usedTabBars.isEmpty()) { + /* + 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 + docking areas haven't been put in the cache yet. + */ + activate(); + } + QTabBar *result = nullptr; if (!unusedTabBars.isEmpty()) { result = unusedTabBars.takeLast();