From 212e961fc8abefb23f5de3c6057556caeeacdc30 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 14 Mar 2014 10:10:13 +0100 Subject: [PATCH] Fix crash when appending arrays to sub models in list models The elements are still inaccessible, but at least it doesn't crash. This is consistent with the behavior in Qt 5.0, where it didn't crash because the v8 object handle returned an empty array for the property names because the individual array element wasn't an object. Bug QTBUG-12117 tracks support for arrays in list models. Task-number: QTBUG-35891 Change-Id: Ief446341344977a1473bca474ca5ba934e950468 Reviewed-by: Albert Astals Cid Reviewed-by: Lars Knoll --- src/qml/types/qqmllistmodel.cpp | 3 +++ tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp index 37742a3667..4a382a1dc5 100644 --- a/src/qml/types/qqmllistmodel.cpp +++ b/src/qml/types/qqmllistmodel.cpp @@ -486,6 +486,9 @@ void ListModel::set(int elementIndex, QV4::ObjectRef object, QVector *roles void ListModel::set(int elementIndex, QV4::ObjectRef object, QV8Engine *eng) { + if (!object) + return; + ListElement *e = elements[elementIndex]; QV4::ExecutionEngine *v4 = object->engine(); diff --git a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp index bdc0646b8e..787aa0f7da 100644 --- a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp +++ b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp @@ -528,6 +528,8 @@ void tst_qqmllistmodel::dynamic_data() QTest::newRow("nested-count") << "{append({'foo':123,'bars':[{'a':1},{'a':2},{'a':3}]}); get(0).bars.count}" << 3 << "" << dr; QTest::newRow("nested-clear") << "{append({'foo':123,'bars':[{'a':1},{'a':2},{'a':3}]}); get(0).bars.clear(); get(0).bars.count}" << 0 << "" << dr; } + + QTest::newRow("jsarray") << "{append({'foo':['1', '2', '3']});get(0).foo.get(0)}" << 0 << "" << false; } void tst_qqmllistmodel::dynamic()