aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlproperty.cpp
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2023-05-09 09:56:06 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2023-05-09 21:28:07 +0200
commit57e272fbd2bb4af083c640e8721e5ecbe869e384 (patch)
tree6ec73c436f073657748fc4d27fdbe9feb676d1cc /src/qml/qml/qqmlproperty.cpp
parent71b4a5e6dfe07fe30c59b3e84c9db27f443a7b92 (diff)
Value types: Prefer assigning bindings instead of converting
When we're assigning a QJSValue to a value type property, we must first check whether it is a binding created by Qt.binding. In that case, we should directly set that binding up. Going through the conversion code path might not necessarily fail, but might instead yield nonsense. Pick-to: 6.5 Fixes: QTBUG-113472 Change-Id: If91e0843f0caf36c96b4c811b9ce8076adfc984f Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlproperty.cpp')
-rw-r--r--src/qml/qml/qqmlproperty.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp
index 0e0d798537..ba82449692 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -1373,6 +1373,18 @@ static ConvertAndAssignResult tryConvertAndAssign(
return {false, false};
}
+ if (variantMetaType == QMetaType::fromType<QJSValue>()) {
+ // Handle Qt.binding bindings here to avoid mistaken conversion below
+ const QJSValue &jsValue = get<QJSValue>(value);
+ const QV4::FunctionObject *f
+ = QJSValuePrivate::asManagedType<QV4::FunctionObject>(&jsValue);
+ if (f && f->isBinding()) {
+ QV4::QObjectWrapper::setProperty(
+ f->engine(), object, &property, f->asReturnedValue());
+ return {true, true};
+ }
+ }
+
// common cases:
switch (propertyMetaType.id()) {
case QMetaType::Bool:
@@ -1597,16 +1609,6 @@ bool QQmlPropertyPrivate::write(
sequence.addValue(list.data(), value.data());
property.writeProperty(object, list.data(), flags);
}
- } else if (variantMetaType == QMetaType::fromType<QJSValue>()) {
- QJSValue jsValue = qvariant_cast<QJSValue>(value);
- const QV4::FunctionObject *f
- = QJSValuePrivate::asManagedType<QV4::FunctionObject>(&jsValue);
- if (f && f->isBinding()) {
- QV4::QObjectWrapper::setProperty(
- f->engine(), object, &property, f->asReturnedValue());
- return true;
- }
- return false;
} else if (enginePriv && propertyMetaType == QMetaType::fromType<QJSValue>()) {
// We can convert everything into a QJSValue if we have an engine.
QJSValue jsValue = QJSValuePrivate::fromReturnedValue(