} else if (d->IsNumber()) {
roleIndex = setDoubleProperty(role, d->NumberValue());
} else if (d->IsArray()) {
- ListModel *subModel = new ListModel(role.subLayout, 0, -1);
- v8::Handle<v8::Array> subArray = v8::Handle<v8::Array>::Cast(d);
- int arrayLength = subArray->Length();
- for (int j=0 ; j < arrayLength ; ++j) {
- v8::Handle<v8::Object> subObject = subArray->Get(j)->ToObject();
- subModel->append(subObject, eng);
+ if (role.type == ListLayout::Role::List) {
+ ListModel *subModel = new ListModel(role.subLayout, 0, -1);
+ v8::Handle<v8::Array> subArray = v8::Handle<v8::Array>::Cast(d);
+ int arrayLength = subArray->Length();
+ for (int j=0 ; j < arrayLength ; ++j) {
+ v8::Handle<v8::Object> subObject = subArray->Get(j)->ToObject();
+ subModel->append(subObject, eng);
+ }
+ roleIndex = setListProperty(role, subModel);
+ } else {
+ qmlInfo(0) << QString::fromLatin1("Can't assign to existing role '%1' of different type [%2 -> %3]").arg(role.name).arg(roleTypeName(role.type)).arg(roleTypeName(ListLayout::Role::List));
}
- roleIndex = setListProperty(role, subModel);
} else if (d->IsBoolean()) {
roleIndex = setBoolProperty(role, d->BooleanValue());
} else if (d->IsObject()) {
void role_mode();
void dynamic_role();
void dynamic_role_data();
+ void string_to_list_crash();
};
bool tst_qquicklistmodel::compareVariantList(const QVariantList &testList, QVariant object)
qApp->processEvents();
}
+void tst_qquicklistmodel::string_to_list_crash()
+{
+ QQmlEngine engine;
+ QQuickListModel model;
+ QQmlEngine::setContextForObject(&model,engine.rootContext());
+ engine.rootContext()->setContextObject(&model);
+ QString script = QLatin1String("{append({'a':'data'});get(0).a = [{'x':123}]}");
+ QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: Can't assign to existing role 'a' of different type [String -> List]");
+ QQmlExpression e(engine.rootContext(), &model, script);
+ // Don't crash!
+ e.evaluate();
+}
+
QTEST_MAIN(tst_qquicklistmodel)
#include "tst_qquicklistmodel.moc"