aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2012-01-27 11:33:37 +1000
committerQt by Nokia <qt-info@nokia.com>2012-03-15 00:22:45 +0100
commitb06108350b1390b51886474628e03e2e84640548 (patch)
treebbf00677d9edc64e2549f2cc3ee42f1edd5a50f4 /tests
parenta27fd584df0ec3d1d072501d8fefe576a97a2e53 (diff)
Ensure that dynamic property storing QObject ptr notifies on delete
Previously, when a QObject ptr was stored in a dynamic variant property, the value of the property could change (to a zero ptr) if the QObject was deleted without a notify signal being emitted by the QDeclarativeVMEMetaObject which stores the property. This commit ensures that such a notify signal is emitted correctly. Task-number: QTBUG-23451 Change-Id: I5689abd984b177737f8d5f18950838b73ebde328 Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmlecmascript/data/dynamicDeletion.3.qml30
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp22
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;
+ }
}
/*