Allow objects created in QML with incubateObject to be destroyed.
authorMichael Brasser <michael.brasser@nokia.com>
Tue, 3 Apr 2012 01:50:05 +0000 (11:50 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 3 Apr 2012 05:50:17 +0000 (07:50 +0200)
Change-Id: I8a0678ea8dff6f4a40ac367395a99dd025f7f08a
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
src/qml/qml/qqmlcomponent.cpp
tests/auto/qml/qqmlecmascript/data/ownershipQmlIncubated.qml [new file with mode: 0644]
tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp

index 7bddaad..2e46192 100644 (file)
@@ -1396,7 +1396,8 @@ void QV8IncubatorResource::statusChanged(Status s)
 {
     if (s == Ready) {
         Q_ASSERT(QQmlData::get(object()));
-        QQmlData::get(object())->setImplicitDestructible();
+        QQmlData::get(object())->explicitIndestructibleSet = false;
+        QQmlData::get(object())->indestructible = false;
     }
 
     if (!me.IsEmpty()) { // Will be false in synchronous mode
diff --git a/tests/auto/qml/qqmlecmascript/data/ownershipQmlIncubated.qml b/tests/auto/qml/qqmlecmascript/data/ownershipQmlIncubated.qml
new file mode 100644 (file)
index 0000000..6f536b2
--- /dev/null
@@ -0,0 +1,27 @@
+import QtQuick 2.0
+
+Item {
+    id: root
+
+    property QtObject incubatedItem
+
+    Component.onCompleted: {
+        var component = Qt.createComponent("PropertyVarBaseItem.qml");
+
+        var incubator = component.incubateObject(root);
+        if (incubator.status != Component.Ready) {
+            incubator.onStatusChanged = function(status) {
+                if (status == Component.Ready) {
+                    incubatedItem = incubator.object;
+                }
+            }
+        } else {
+            incubatedItem = incubator.object;
+        }
+    }
+
+    function deleteIncubatedItem() {
+        incubatedItem.destroy();
+        gc();
+    }
+}
index 6b10672..5842ab0 100644 (file)
@@ -135,6 +135,7 @@ private slots:
     void ownershipCustomReturnValue();
     void ownershipRootObject();
     void ownershipConsistency();
+    void ownershipQmlIncubated();
     void qlistqobjectMethods();
     void strictlyEquals();
     void compiled();
@@ -3018,6 +3019,24 @@ void tst_qqmlecmascript::ownershipConsistency()
     delete object;
 }
 
+void tst_qqmlecmascript::ownershipQmlIncubated()
+{
+    QQmlComponent component(&engine, testFileUrl("ownershipQmlIncubated.qml"));
+    QObject *object = component.create();
+    QVERIFY(object);
+
+    QTRY_VERIFY(object->property("incubatedItem").value<QObject*>() != 0);
+
+    QMetaObject::invokeMethod(object, "deleteIncubatedItem");
+
+    QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
+    QCoreApplication::processEvents();
+
+    QVERIFY(object->property("incubatedItem").value<QObject*>() == 0);
+
+    delete object;
+}
+
 class QListQObjectMethodsObject : public QObject
 {
     Q_OBJECT