aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2018-03-19 17:01:21 +0100
committerSimon Hausmann <simon.hausmann@qt.io>2018-03-20 07:34:07 +0000
commit1de4d413c9dd5c8ad5859f944d9ded7d8778f777 (patch)
tree6868c70acc964b6269e753cf5f0c1e94ec519e34 /src/qml
parenta07d2f21a4d445fae7a7cc130e45a8fd72997713 (diff)
Fix assigning objects to QJSValue properties
We support simple object bindings such as someProperty: Rectangle { ... } when the type of "someProperty" is QVariant, but we produce an error when it's QJSValue. There is no good reason for that, and the fix for QTBUG-67118 requires this. Change-Id: Ia5dc88749bcba0b5c781a6ab2b4a9fb92299e0ac Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/compiler/qqmlpropertyvalidator.cpp2
-rw-r--r--src/qml/qml/qqmlobjectcreator.cpp12
2 files changed, 13 insertions, 1 deletions
diff --git a/src/qml/compiler/qqmlpropertyvalidator.cpp b/src/qml/compiler/qqmlpropertyvalidator.cpp
index 00bb694ef4..ffd3b5975a 100644
--- a/src/qml/compiler/qqmlpropertyvalidator.cpp
+++ b/src/qml/compiler/qqmlpropertyvalidator.cpp
@@ -653,7 +653,7 @@ QQmlCompileError QQmlPropertyValidator::validateObjectBinding(QQmlPropertyData *
// Can only check at instantiation time if the created sub-object successfully casts to the
// target interface.
return noError;
- } else if (property->propType() == QMetaType::QVariant) {
+ } else if (property->propType() == QMetaType::QVariant || property->propType() == qMetaTypeId<QJSValue>()) {
// We can convert everything to QVariant :)
return noError;
} else if (property->isQList()) {
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp
index 90f3beb40b..7051fb51da 100644
--- a/src/qml/qml/qqmlobjectcreator.cpp
+++ b/src/qml/qml/qqmlobjectcreator.cpp
@@ -55,6 +55,7 @@
#include <private/qqmlvaluetypeproxybinding_p.h>
#include <private/qqmldebugconnector_p.h>
#include <private/qqmldebugserviceinterfaces_p.h>
+#include <private/qjsvalue_p.h>
QT_USE_NAMESPACE
@@ -1039,6 +1040,17 @@ bool QQmlObjectCreator::setPropertyBinding(const QQmlPropertyData *bindingProper
argv[0] = &value;
QMetaObject::metacall(_qobject, QMetaObject::WriteProperty, bindingProperty->coreIndex(), argv);
}
+ } else if (bindingProperty->propType() == qMetaTypeId<QJSValue>()) {
+ QV4::Scope scope(v4);
+ QV4::ScopedValue wrappedObject(scope, QV4::QObjectWrapper::wrap(engine->handle(), createdSubObject));
+ if (bindingProperty->isVarProperty()) {
+ _vmeMetaObject->setVMEProperty(bindingProperty->coreIndex(), wrappedObject);
+ } else {
+ QJSValue value;
+ QJSValuePrivate::setValue(&value, v4, wrappedObject);
+ argv[0] = &value;
+ QMetaObject::metacall(_qobject, QMetaObject::WriteProperty, bindingProperty->coreIndex(), argv);
+ }
} else if (bindingProperty->isQList()) {
Q_ASSERT(_currentList.object);