diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmlecmascript/data/dynamicDeletion.3.qml | 30 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 22 |
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/dynamicDeletion.3.qml b/tests/auto/qml/qqmlecmascript/data/dynamicDeletion.3.qml new file mode 100644 index 0000000000..3739150bc4 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/dynamicDeletion.3.qml @@ -0,0 +1,30 @@ +import QtQuick 2.0 +import Qt.test 1.0 + +Item { + id: root + property bool test: false + property QtObject objectProperty + + onObjectPropertyChanged: { + root.test = true; + } + + property Component c: Component { + id: dynamicComponent + QtObject { + id: dynamicObject + } + } + + function create() { + root.objectProperty = root.c.createObject(root); + } + + function destroy() { + root.test = false; // reset test + root.objectProperty.destroy(100); + // in cpp, wait objectProperty deletion, inspect "test" and "objectProperty" + // test should be true and value of objectProperty should be zero. + } +} diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 8fea635b68..e3ad1e71cb 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -1288,6 +1288,28 @@ void tst_qqmlecmascript::dynamicDestruction() delete o; } + + { + // QTBUG-23451 + QQmlGuard<QObject> createdQmlObject = 0; + QQmlComponent component(&engine, testFileUrl("dynamicDeletion.3.qml")); + QObject *o = component.create(); + QVERIFY(o != 0); + QVERIFY(qvariant_cast<QObject*>(o->property("objectProperty")) == 0); + QMetaObject::invokeMethod(o, "create"); + createdQmlObject = qvariant_cast<QObject*>(o->property("objectProperty")); + QVERIFY(createdQmlObject); + QMetaObject::invokeMethod(o, "destroy"); + QVERIFY(qvariant_cast<bool>(o->property("test")) == false); + for (int ii = 0; createdQmlObject && ii < 50; ++ii) { // After 5 seconds we should give up + QTest::qWait(100); + QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); + QCoreApplication::processEvents(); + } + QVERIFY(qvariant_cast<QObject*>(o->property("objectProperty")) == 0); + QVERIFY(qvariant_cast<bool>(o->property("test")) == true); + delete o; + } } /* |