diff options
author | Thomas Fischer <fischer@unix-ag.uni-kl.de> | 2014-08-24 14:01:26 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2014-09-05 00:05:45 +0200 |
commit | 983dde1f2f3db76ab26e949d8c2f4f8b968b36be (patch) | |
tree | c092b9aa473e4ca41201ab1969f9139ff9db8585 /tests/auto/widgets/kernel/qformlayout | |
parent | 8206a263ab9bca7fef191d299c05294a00ec1c8f (diff) |
Avoid adding widget to its own layout
Widgets and layouts added or inserted to a layout are checked for:
- Not being NULL
- Not being the parent widget of a layout or the layout itself,
respectively
Without this commit, adding a widget to its own layout would result in a
CPU-hogging infinite loop. Now, a warning is written to stderr and the
add or insert function call is ignored.
The checks are implemented as public functions of QLayoutPrivate and
thus accessible in QLayout's descendants to be used in various
"addWidget", "insertWidget", etc functions.
Unlike 'classical' layouts like QGridLayout, QFormLayout does indeed
accept widgets that are NULL. To not break this behavior, any call for
the check functions first tests if the widget or layout, respectively,
to test is NULL or not and calls the check only in the latter case.
Automated tests for QBoxLayout, QGridLayout, and QFormLayout were added.
For an unpatched Qt 5.3, each of those automated tests will freeze as
explained in QTBUG-40609. For a fixed version, warning messages about
invalid parameters to addWidget/addLayout/... calls will be read by
QTest::ignoreMessage, resulting in a passed test.
Change-Id: I1522d5727e643da3f7c025755975aca9f482676d
Task-number: QTBUG-40609
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'tests/auto/widgets/kernel/qformlayout')
-rw-r--r-- | tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp index 9df7e1662d..962e472606 100644 --- a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp +++ b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp @@ -135,6 +135,8 @@ private slots: */ void taskQTBUG_27420_takeAtShouldUnparentLayout(); + void taskQTBUG_40609_addingWidgetToItsOwnLayout(); + void taskQTBUG_40609_addingLayoutToItself(); }; @@ -949,6 +951,28 @@ void tst_QFormLayout::taskQTBUG_27420_takeAtShouldUnparentLayout() QVERIFY(!inner.isNull()); } +void tst_QFormLayout::taskQTBUG_40609_addingWidgetToItsOwnLayout(){ + QWidget widget; + widget.setObjectName("6435cbada60548b4522cbb6"); + QFormLayout layout(&widget); + layout.setObjectName("c03c0e22c0b6d019a93a248"); + + QTest::ignoreMessage(QtWarningMsg, "QLayout: Cannot add parent widget QWidget/6435cbada60548b4522cbb6 to its child layout QFormLayout/c03c0e22c0b6d019a93a248"); + layout.addRow(QLatin1String("48c81f39b7320082f8"), &widget); + QCOMPARE(layout.count(), 0); +} + +void tst_QFormLayout::taskQTBUG_40609_addingLayoutToItself(){ + QWidget widget; + widget.setObjectName("2bc425637d084c07ce65956"); + QFormLayout layout(&widget); + layout.setObjectName("60e31de0c8800eaba713a4f2"); + + QTest::ignoreMessage(QtWarningMsg, "QLayout: Cannot add layout QFormLayout/60e31de0c8800eaba713a4f2 to itself"); + layout.addRow(QLatin1String("9a2cd4f40c06b489f889"), &layout); + QCOMPARE(layout.count(), 0); +} + void tst_QFormLayout::replaceWidget() { QWidget w; |