summaryrefslogtreecommitdiffstats
path: root/tests
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-11 19:02:30 +0000
commitaba4da8a0ecdaef80c23cdfaa2b5c3f093198e07 (patch)
tree261982c5874039cf690687fc719d8c5a55b15dab /tests
parent242f8ef98527a9e25c8b028382eb4e16fe0ae8d7 (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 'tests')
-rw-r--r--tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp b/tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp
index 2a497df084..2028338d20 100644
--- a/tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp
+++ b/tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp
@@ -69,6 +69,7 @@ private slots:
void controlTypes2();
void adjustSizeShouldMakeSureLayoutIsActivated();
void testRetainSizeWhenHidden();
+ void removeWidget();
};
tst_QLayout::tst_QLayout()
@@ -381,5 +382,28 @@ void tst_QLayout::testRetainSizeWhenHidden()
QCOMPARE(widget.sizeHint().height(), normalHeight);
}
+void tst_QLayout::removeWidget()
+{
+ QHBoxLayout layout;
+ QCOMPARE(layout.count(), 0);
+ QWidget w;
+ layout.addWidget(&w);
+ QCOMPARE(layout.count(), 1);
+ layout.removeWidget(&w);
+ QCOMPARE(layout.count(), 0);
+
+ QPointer<QLayout> childLayout(new QHBoxLayout);
+ layout.addLayout(childLayout);
+ QCOMPARE(layout.count(), 1);
+
+ layout.removeWidget(nullptr);
+ QCOMPARE(layout.count(), 1);
+
+ layout.removeItem(childLayout);
+ QCOMPARE(layout.count(), 0);
+
+ QVERIFY(!childLayout.isNull());
+}
+
QTEST_MAIN(tst_QLayout)
#include "tst_qlayout.moc"