diff options
3 files changed, 47 insertions, 0 deletions
diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index e99928d862..b6bcc64afa 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -748,6 +748,10 @@ void QDeclarativeComponent::createObject(QDeclarativeV8Function *args) completeCreate(); + QDeclarativeData *ddata = QDeclarativeData::get(ret); + Q_ASSERT(ddata); + ddata->setImplicitDestructible(); + RETURN(object); #undef RETURN diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/dynamicDeletion.2.qml b/tests/auto/declarative/qdeclarativeecmascript/data/dynamicDeletion.2.qml new file mode 100644 index 0000000000..70c281691b --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/dynamicDeletion.2.qml @@ -0,0 +1,21 @@ +import QtQuick 1.0 + +QtObject { + id: root + + property QtObject objectProperty + + property Component c: Component { + id: componentObject + QtObject { + } + } + + function create() { + objectProperty = c.createObject(root); + } + + function destroy() { + objectProperty.destroy(); + } +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index bc33932442..b1bc5bda2b 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -1074,6 +1074,7 @@ void tst_qdeclarativeecmascript::dynamicCreation() */ void tst_qdeclarativeecmascript::dynamicDestruction() { + { QDeclarativeComponent component(&engine, TEST_FILE("dynamicDeletion.qml")); QDeclarativeGuard<MyQmlObject> object = qobject_cast<MyQmlObject*>(component.create()); QVERIFY(object != 0); @@ -1102,6 +1103,27 @@ void tst_qdeclarativeecmascript::dynamicDestruction() QTest::qWait(0); QCoreApplication::instance()->processEvents(QEventLoop::DeferredDeletion); QVERIFY(!object); + } + + { + QDeclarativeComponent component(&engine, TEST_FILE("dynamicDeletion.2.qml")); + QObject *o = component.create(); + QVERIFY(o != 0); + + QVERIFY(qvariant_cast<QObject*>(o->property("objectProperty")) == 0); + + QMetaObject::invokeMethod(o, "create"); + + QVERIFY(qvariant_cast<QObject*>(o->property("objectProperty")) != 0); + + QMetaObject::invokeMethod(o, "destroy"); + + QCoreApplication::instance()->processEvents(QEventLoop::DeferredDeletion); + + QVERIFY(qvariant_cast<QObject*>(o->property("objectProperty")) == 0); + + delete o; + } } /* |