aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2020-01-10 15:22:20 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2020-01-28 09:47:56 +0100
commit03df41fbcdb6e1ae3d0792d5b7806e5335b58794 (patch)
tree9ac6e33306be9d368f4016aa689d42d67e17bfd6 /tests
parentddeffeed1d933b6513f18533a9186e9f472da117 (diff)
QML list property: Avoid crash if contained object is deleted
Task-number: QTBUG-81123 Change-Id: I3dd1a42e444f817722368cd268c2f987a99fbf1c Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit e5570eecd3a4fc61020d28699169707a2c1f5dc9)
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmllanguage/data/listContainingDeleted.qml36
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp20
2 files changed, 56 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/data/listContainingDeleted.qml b/tests/auto/qml/qqmllanguage/data/listContainingDeleted.qml
new file mode 100644
index 0000000000..efd273ddc6
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/listContainingDeleted.qml
@@ -0,0 +1,36 @@
+import QtQuick 2.12
+
+Item {
+ width: 1024
+ height: 800
+
+ property Component a: Component {
+ id: a
+ Item {
+ property list<QtObject> myList: [
+ QtObject {
+ property bool enabled: true
+ }
+ ]
+ }
+ }
+ Component {
+ id: b
+ Item {
+ property list<QtObject> myList
+
+ function test() {
+ for (var i = 0; i < myList.length; ++i)
+ console.log(i, "==", myList[i].enabled)
+ }
+ }
+ }
+ property Item instance
+ function doAssign(o) {
+ instance = b.createObject(null, {myList: o.myList})
+ }
+ function use() {
+ instance.test()
+ }
+
+}
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
index 87468c329c..d7ef9999d0 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -303,6 +303,8 @@ private slots:
void typeWrapperToVariant();
+ void listContainingDeletedObject();
+
private:
QQmlEngine engine;
QStringList defaultImportPathList;
@@ -5100,6 +5102,24 @@ void tst_qqmllanguage::typeWrapperToVariant()
QVERIFY(target);
}
+void tst_qqmllanguage::listContainingDeletedObject()
+{
+ QQmlEngine engine;
+ auto url = testFileUrl("listContainingDeleted.qml");
+ const QString message = url.toString() + ":24: TypeError: Cannot read property 'enabled' of null";
+ QTest::ignoreMessage(QtMsgType::QtWarningMsg, message.toUtf8().data());
+ QQmlComponent comp(&engine, url);
+ QScopedPointer<QObject> root(comp.create());
+ QVERIFY(root);
+
+ auto cmp = root->property("a").value<QQmlComponent*>();
+ auto o = cmp->create();
+
+ QMetaObject::invokeMethod(root.get(), "doAssign", Q_ARG(QVariant, QVariant::fromValue(o)));
+ delete o;
+ QMetaObject::invokeMethod(root.get(), "use");
+
+}
QTEST_MAIN(tst_qqmllanguage)
#include "tst_qqmllanguage.moc"