aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp')
-rw-r--r--tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
index 37b0f6f1fe..fbdf6d90f3 100644
--- a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
+++ b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
@@ -139,6 +139,7 @@ private slots:
void listElementWithTemplateString();
void destroyComponentObject();
void objectOwnershipFlip();
+ void protectQObjectFromGC();
};
bool tst_qqmllistmodel::compareVariantList(const QVariantList &testList, QVariant object)
@@ -1882,7 +1883,7 @@ void tst_qqmllistmodel::destroyComponentObject()
Q_RETURN_ARG(QVariant, retVal));
QVERIFY(retVal.toBool());
QTRY_VERIFY(created.isNull());
- QTRY_VERIFY(list->get(0).property("obj").isUndefined());
+ QTRY_VERIFY(list->get(0).property("obj").isNull());
QCOMPARE(list->count(), 1);
}
@@ -1920,6 +1921,25 @@ void tst_qqmllistmodel::objectOwnershipFlip()
QCOMPARE(QJSEngine::objectOwnership(item.data()), QJSEngine::CppOwnership);
}
+void tst_qqmllistmodel::protectQObjectFromGC()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("protectQObjectFromGC.qml"));
+ QVERIFY2(component.isReady(), qPrintable(component.errorString()));
+ QScopedPointer<QObject> root(component.create());
+ QVERIFY(!root.isNull());
+
+ QQmlListModel *listModel = qobject_cast<QQmlListModel *>(root.data());
+ QVERIFY(listModel);
+ QCOMPARE(listModel->count(), 10);
+
+ for (int i = 0; i < 10; ++i) {
+ QObject *element = qjsvalue_cast<QObject *>(listModel->get(i).property("path"));
+ QVERIFY(element);
+ QCOMPARE(element->property("name").toString(), QString::number(i));
+ }
+}
+
QTEST_MAIN(tst_qqmllistmodel)
#include "tst_qqmllistmodel.moc"