Skip to content

Commit

Permalink
Mark objects from Component.createObject() as destructible
Browse files Browse the repository at this point in the history
Change-Id: I00a1a2b5cca80c3e2ea097690cadf21581e1356d
Task-number: QTBUG-20626
Reviewed-on: http://codereview.qt.nokia.com/2367
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
  • Loading branch information
Aaron Kennedy authored and Qt by Nokia committed Jul 29, 2011
1 parent 8fed8bf commit 0e68a62
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/declarative/qml/qdeclarativecomponent.cpp
Expand Up @@ -748,6 +748,10 @@ void QDeclarativeComponent::createObject(QDeclarativeV8Function *args)

completeCreate();

QDeclarativeData *ddata = QDeclarativeData::get(ret);
Q_ASSERT(ddata);
ddata->setImplicitDestructible();

RETURN(object);

#undef RETURN
Expand Down
@@ -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();
}
}
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}

/*
Expand Down

0 comments on commit 0e68a62

Please sign in to comment.