From 3dbe05f6bf3fd51ce8097c35f6c7f12b39acb0f6 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 10 Sep 2014 17:13:10 +0200 Subject: Fix mapping of JS objects/arrays to C++ [ChangeLog][QtQml][Important Behavior Changes] When a JavaScript object/array is passed to C++ through a QVariant, the engine no longer immediately converts the object recursively into a QVariantMap or QVariantList but instead stores a QJSValue in the QVariant. This prevents a loss of data when the JS object contains non-primitive types such as function objects for example. Code that expects the variant type to be exactly QVariant::Map or QVariant::List may need to be adapted. Registered conversion functions however ensure that code that merely calls toMap() or toList() continues to work. Task-number: QTBUG-40431 Change-Id: I1dbc1d5f8e78ad28bb62db3681b9a0b34557e7f5 Reviewed-by: Lars Knoll --- src/qml/util/qqmllistaccessor.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/qml/util') diff --git a/src/qml/util/qqmllistaccessor.cpp b/src/qml/util/qqmllistaccessor.cpp index e434d6cef4..5a199abf44 100644 --- a/src/qml/util/qqmllistaccessor.cpp +++ b/src/qml/util/qqmllistaccessor.cpp @@ -61,6 +61,11 @@ void QQmlListAccessor::setList(const QVariant &v, QQmlEngine *engine) { d = v; + // An incoming JS array as model is treated as a variant list, so we need to + // convert it first with toVariant(). + if (d.userType() == qMetaTypeId()) + d = d.value().toVariant(); + QQmlEnginePrivate *enginePrivate = engine?QQmlEnginePrivate::get(engine):0; if (!d.isValid()) { @@ -73,7 +78,7 @@ void QQmlListAccessor::setList(const QVariant &v, QQmlEngine *engine) m_type = Integer; } else if ((!enginePrivate && QQmlMetaType::isQObject(d.userType())) || (enginePrivate && enginePrivate->isQObject(d.userType()))) { - QObject *data = enginePrivate?enginePrivate->toQObject(v):QQmlMetaType::toQObject(v); + QObject *data = enginePrivate?enginePrivate->toQObject(d):QQmlMetaType::toQObject(d); d = QVariant::fromValue(data); m_type = Instance; } else if (d.userType() == qMetaTypeId()) { -- cgit v1.2.3