diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-10-28 13:41:11 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-10-29 07:00:49 +0000 |
commit | 73ad6e87bbeceea5830ab3a6b3dc66fa99e30f45 (patch) | |
tree | 6eadb286cccad0ccd736a23b3836a27b3e839200 /tests | |
parent | 76b86342d47df953009457a554245aace49eecf6 (diff) |
QQuickItem::setParentItem: add child earlier
Calling (de)refWindow can trigger QQuickItem::windowChanged, which in turn
can call a user defined windowChanged handler. If that signal handler
were to call setParentItem, we would encounter an inconsistent state:
The item already has its parent set, but that parent would lack the item
in its children list (as we would only call refWindow at a later point).
Fixes: QTBUG-79573
Fixes: QTBUG-73439
Change-Id: I46adaa54a0521b5cd7f37810b3dd1a206e6a09c6
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquickitem/data/setParentInWindowChange.qml | 12 | ||||
-rw-r--r-- | tests/auto/quick/qquickitem/tst_qquickitem.cpp | 8 |
2 files changed, 20 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickitem/data/setParentInWindowChange.qml b/tests/auto/quick/qquickitem/data/setParentInWindowChange.qml new file mode 100644 index 0000000000..d68b7adb72 --- /dev/null +++ b/tests/auto/quick/qquickitem/data/setParentInWindowChange.qml @@ -0,0 +1,12 @@ +import QtQuick 2.12 + +Rectangle { + width: 800 + height: 600 + Item { + id: it + onWindowChanged: () => it.parent = newParent + } + + Item { id: newParent } +} diff --git a/tests/auto/quick/qquickitem/tst_qquickitem.cpp b/tests/auto/quick/qquickitem/tst_qquickitem.cpp index 7e132f97b6..9ce9766c92 100644 --- a/tests/auto/quick/qquickitem/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem/tst_qquickitem.cpp @@ -197,6 +197,8 @@ private slots: void qtBug60123(); #endif + void setParentCalledInOnWindowChanged(); + private: enum PaintOrderOp { @@ -2145,6 +2147,12 @@ void tst_qquickitem::qtBug60123() activateWindowAndTestPress(&window); } #endif +void tst_qquickitem::setParentCalledInOnWindowChanged() +{ + QQuickView view; + view.setSource(testFileUrl("setParentInWindowChange.qml")); + QVERIFY(ensureFocus(&view)); // should not crash +} QTEST_MAIN(tst_qquickitem) |