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 <albert.astals@canonical.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
Simon Hausmann 2014-03-14 10:10:13 +01:00 committed by The Qt Project
parent 1656d6006b
commit 212e961fc8
2 changed files with 5 additions and 0 deletions

View File

@ -486,6 +486,9 @@ void ListModel::set(int elementIndex, QV4::ObjectRef object, QVector<int> *roles
void ListModel::set(int elementIndex, QV4::ObjectRef object, QV8Engine *eng)
{
if (!object)
return;
ListElement *e = elements[elementIndex];
QV4::ExecutionEngine *v4 = object->engine();

View File

@ -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()