From 146658a10f290603470b800d71b778239e764312 Mon Sep 17 00:00:00 2001 From: Jan Arve Saether Date: Tue, 23 Apr 2013 15:04:26 +0200 Subject: Fixed QLayout::addChildLayout(QLayout *l) when l had a parent Previously if l had a parent, addChildLayout would warn and skip the reparenting, but it would still add the sub layout to the layout. This caused some inconsistencies in the hierarchy which in worst case could cause crashes. Task-number: QTBUG-30758 Change-Id: I618ec3341636b97bd71e421201b22c746dcf43e1 Reviewed-by: Paul Olav Tvete --- .../widgets/kernel/qboxlayout/tst_qboxlayout.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/auto/widgets/kernel/qboxlayout') diff --git a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp index 227a31b10d..84d796f657 100644 --- a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp +++ b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp @@ -68,6 +68,7 @@ public slots: private slots: void insertSpacerItem(); + void insertLayout(); void sizeHint(); void sizeConstraints(); void setGeometry(); @@ -166,6 +167,26 @@ void tst_QBoxLayout::insertSpacerItem() window->show(); } +void tst_QBoxLayout::insertLayout() +{ + QWidget *window = new QWidget; + QVBoxLayout *vbox = new QVBoxLayout(window); + QVBoxLayout *dummyParentLayout = new QVBoxLayout; + QHBoxLayout *subLayout = new QHBoxLayout; + dummyParentLayout->addLayout(subLayout); + QCOMPARE(subLayout->parent(), dummyParentLayout); + QCOMPARE(dummyParentLayout->count(), 1); + + // add subLayout to another layout + QTest::ignoreMessage(QtWarningMsg, "QLayout::addChildLayout: layout \"\" already has a parent"); + vbox->addLayout(subLayout); + QCOMPARE((subLayout->parent() == vbox), (vbox->count() == 1)); + + delete dummyParentLayout; + delete window; +} + + void tst_QBoxLayout::sizeHint() { QWidget *window = new QWidget; -- cgit v1.2.3