From 817c0741d1d3e1dc1c505652ba764fe96b584aac Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 3 Apr 2012 11:50:05 +1000 Subject: [PATCH] Allow objects created in QML with incubateObject to be destroyed. Change-Id: I8a0678ea8dff6f4a40ac367395a99dd025f7f08a Reviewed-by: Chris Adams --- src/qml/qml/qqmlcomponent.cpp | 3 ++- .../qqmlecmascript/data/ownershipQmlIncubated.qml | 27 ++++++++++++++++++++++ .../auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 19 +++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tests/auto/qml/qqmlecmascript/data/ownershipQmlIncubated.qml diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp index 7bddaad..2e46192 100644 --- a/src/qml/qml/qqmlcomponent.cpp +++ b/src/qml/qml/qqmlcomponent.cpp @@ -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 index 0000000..6f536b2 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/ownershipQmlIncubated.qml @@ -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(); + } +} diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 6b10672..5842ab0 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -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() != 0); + + QMetaObject::invokeMethod(object, "deleteIncubatedItem"); + + QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); + QCoreApplication::processEvents(); + + QVERIFY(object->property("incubatedItem").value() == 0); + + delete object; +} + class QListQObjectMethodsObject : public QObject { Q_OBJECT -- 2.7.4