aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qmlmodels/qqmllistmodel.cpp2
-rw-r--r--tests/auto/qml/qqmllistmodel/data/destroyObject.qml23
-rw-r--r--tests/auto/qml/qqmllistmodel/data/dummyItem.qml5
-rw-r--r--tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp26
4 files changed, 55 insertions, 1 deletions
diff --git a/src/qmlmodels/qqmllistmodel.cpp b/src/qmlmodels/qqmllistmodel.cpp
index a9c58d59a5..b71931cc85 100644
--- a/src/qmlmodels/qqmllistmodel.cpp
+++ b/src/qmlmodels/qqmllistmodel.cpp
@@ -1112,7 +1112,7 @@ static void setQObjectOwnership(char *mem, QObject *o)
if (!ddata)
ddata = QQmlData::get(o, true);
- ddata->indestructible = true;
+ ddata->indestructible = ownership != 0;
ddata->explicitIndestructibleSet = false;
new (mem) ListElement::GuardedQObjectPointer(
diff --git a/tests/auto/qml/qqmllistmodel/data/destroyObject.qml b/tests/auto/qml/qqmllistmodel/data/destroyObject.qml
new file mode 100644
index 0000000000..e6b3f33bb9
--- /dev/null
+++ b/tests/auto/qml/qqmllistmodel/data/destroyObject.qml
@@ -0,0 +1,23 @@
+import QtQml
+
+QtObject {
+ id: root
+ property ListModel projects: ListModel {}
+ property var object
+
+ Component.onCompleted: {
+ var comp= Qt.createComponent("dummyItem.qml");
+ object = comp.createObject(root, {});
+ projects.append({"obj": object});
+ }
+
+ function destroy() {
+ try {
+ object.destroy();
+ } catch(e) {
+ console.warn(e);
+ return false;
+ }
+ return true;
+ }
+}
diff --git a/tests/auto/qml/qqmllistmodel/data/dummyItem.qml b/tests/auto/qml/qqmllistmodel/data/dummyItem.qml
new file mode 100644
index 0000000000..c9939efcdf
--- /dev/null
+++ b/tests/auto/qml/qqmllistmodel/data/dummyItem.qml
@@ -0,0 +1,5 @@
+import QtQml
+
+QtObject {
+ property var random: null
+}
diff --git a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
index a9b6ec03a4..7f94180274 100644
--- a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
+++ b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
@@ -136,6 +136,7 @@ private slots:
void destroyObject();
void emptyStringNotUndefined();
void listElementWithTemplateString();
+ void destroyComponentObject();
};
bool tst_qqmllistmodel::compareVariantList(const QVariantList &testList, QVariant object)
@@ -1856,6 +1857,31 @@ void tst_qqmllistmodel::listElementWithTemplateString()
QVERIFY(!root.isNull());
}
+//QTBUG-95895
+void tst_qqmllistmodel::destroyComponentObject()
+{
+ QQmlEngine eng;
+ QQmlComponent component(&eng, testFileUrl("destroyObject.qml"));
+ QVERIFY(!component.isError());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY(!obj.isNull());
+ QQmlListModel *list = qvariant_cast<QQmlListModel *>(obj->property("projects"));
+ QVERIFY(list != nullptr);
+ QCOMPARE(list->count(), 1);
+ QPointer<QObject> created(qvariant_cast<QObject *>(obj->property("object")));
+ QVERIFY(!created.isNull());
+ QCOMPARE(list->get(0).property("obj").toQObject(), created.data());
+ QVariant retVal;
+ QMetaObject::invokeMethod(obj.data(),
+ "destroy",
+ Qt::DirectConnection,
+ Q_RETURN_ARG(QVariant, retVal));
+ QVERIFY(retVal.toBool());
+ QTRY_VERIFY(created.isNull());
+ QTRY_VERIFY(list->get(0).property("obj").isUndefined());
+ QCOMPARE(list->count(), 1);
+}
+
QTEST_MAIN(tst_qqmllistmodel)
#include "tst_qqmllistmodel.moc"