Allow objects created in QML with incubateObject to be destroyed.
Change-Id: I8a0678ea8dff6f4a40ac367395a99dd025f7f08a Reviewed-by: Chris Adams <christopher.adams@nokia.com>
This commit is contained in:
parent
b3264e2cb6
commit
817c0741d1
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue