diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-04-21 17:24:03 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-04-24 17:41:02 +0200 |
commit | 70ad4042033219d9cafc66f7b6365aa0caeeee3e (patch) | |
tree | 155110bf7ddaaaae3e3b24cfef1a6e208dec1a6d /src/widgets/widgets/qmainwindowlayout.cpp | |
parent | ed86a4f25322ab0d08ad8ee9d3c507146573b1e0 (diff) |
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 <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets/widgets/qmainwindowlayout.cpp')
-rw-r--r-- | src/widgets/widgets/qmainwindowlayout.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
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(); |