summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPiotr Srebrny <piotr.srebrny@qt.io>2021-04-28 14:37:44 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-05-26 16:58:34 +0000
commitd90092683eae976736940bb18b175c8cf467a2b6 (patch)
tree2e26ba2d81f050bc4eb600b6f3714669e807c669 /src
parent95694109e9ec8200239f9a9aae7a789fe565c5e9 (diff)
Do not remove non-widget items when removeWidget() called with nullptr
child->widget() returns null if the layout item is not a widget. Thus, calling removeWidget(nullptr) will remove all non-widget items such as layouts or strechers. Change-Id: I772c1158d0f7e8e2850b6e571b0405a2896f09b8 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: David Faure <david.faure@kdab.com> (cherry picked from commit 867c0b8d8a53974074b1fff5b132f3ae9f150066) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/kernel/qlayout.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/widgets/kernel/qlayout.cpp b/src/widgets/kernel/qlayout.cpp
index b034a76bcf..7b79486ff3 100644
--- a/src/widgets/kernel/qlayout.cpp
+++ b/src/widgets/kernel/qlayout.cpp
@@ -1386,6 +1386,11 @@ QRect QLayout::alignmentRect(const QRect &r) const
*/
void QLayout::removeWidget(QWidget *widget)
{
+ if (Q_UNLIKELY(!widget)) {
+ qWarning("QLayout::removeWidget: Cannot remove a null widget.");
+ return;
+ }
+
int i = 0;
QLayoutItem *child;
while ((child = itemAt(i))) {