diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-10-07 10:01:46 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-10-07 11:31:17 +0200 |
commit | 00f903f3b4cd46ddf8361876401e5405030f97f1 (patch) | |
tree | 8ba52e5e8e74557aa5313ddbc6f6fbcb444f1545 /src | |
parent | dce305c4041a6ee65d486f3b31dc49c274ecdcbd (diff) |
QML Binding: do not convert strings
The root cause for the issue is that QQmlObjectCreator::setPropertyValue
calls QQmlStringConverters::variantFromString on strings if the property
is of type QVariant. Unfortunately, this cannot be changed easily as the
current behavior is explicitly documented and tested in tst_qqmllanguage,
thus making it a breaking change.
As a workaround, QML Binding does now take a QJSValue instead of a
QVariant (making value a var property), which does not trigger the
conversion path.
Fixes: QTBUG-78943
Change-Id: I0b64dffdb6b84b2bab2bb85a8cb263e530c18570
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/qml/qqmlobjectcreator.cpp | 2 | ||||
-rw-r--r-- | src/qml/types/qqmlbind.cpp | 8 | ||||
-rw-r--r-- | src/qml/types/qqmlbind_p.h | 6 |
3 files changed, 9 insertions, 7 deletions
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index f89608cd5d..a4270628e8 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -445,6 +445,8 @@ void QQmlObjectCreator::setPropertyValue(const QQmlPropertyData *property, const QV4::ScopedString s(scope, v4->newString(stringValue)); _vmeMetaObject->setVMEProperty(property->coreIndex(), s); } else { + // ### Qt 6: Doing the conversion here where we don't know the eventual target type is rather strange + // and caused for instance QTBUG-78943 QVariant value = QQmlStringConverters::variantFromString(stringValue); property->writeProperty(_qobject, &value, propertyWriteFlags); } diff --git a/src/qml/types/qqmlbind.cpp b/src/qml/types/qqmlbind.cpp index 8f40f4f704..36de16a818 100644 --- a/src/qml/types/qqmlbind.cpp +++ b/src/qml/types/qqmlbind.cpp @@ -78,7 +78,7 @@ public: QQmlNullableValue<bool> when; QPointer<QObject> obj; QString propName; - QQmlNullableValue<QVariant> value; + QQmlNullableValue<QJSValue> value; QQmlProperty prop; QQmlAbstractBinding::Ptr prevBind; QV4::PersistentValue v4Value; @@ -293,13 +293,13 @@ void QQmlBind::setProperty(const QString &p) The value to be set on the target object and property. This can be a constant (which isn't very useful), or a bound expression. */ -QVariant QQmlBind::value() const +QJSValue QQmlBind::value() const { Q_D(const QQmlBind); return d->value.value; } -void QQmlBind::setValue(const QVariant &v) +void QQmlBind::setValue(const QJSValue &v) { Q_D(QQmlBind); d->value = v; @@ -502,7 +502,7 @@ void QQmlBind::eval() QQmlPropertyPrivate::removeBinding(d->prop); } - d->prop.write(d->value.value); + d->prop.write(d->value.value.toVariant()); } QT_END_NAMESPACE diff --git a/src/qml/types/qqmlbind_p.h b/src/qml/types/qqmlbind_p.h index 22007a3d25..ba040d2a0b 100644 --- a/src/qml/types/qqmlbind_p.h +++ b/src/qml/types/qqmlbind_p.h @@ -75,7 +75,7 @@ private: Q_INTERFACES(QQmlPropertyValueSource) Q_PROPERTY(QObject *target READ object WRITE setObject) Q_PROPERTY(QString property READ property WRITE setProperty) - Q_PROPERTY(QVariant value READ value WRITE setValue) + Q_PROPERTY(QJSValue value READ value WRITE setValue) Q_PROPERTY(bool when READ when WRITE setWhen) Q_PROPERTY(bool delayed READ delayed WRITE setDelayed REVISION 8) Q_PROPERTY(RestorationMode restoreMode READ restoreMode WRITE setRestoreMode @@ -95,8 +95,8 @@ public: QString property() const; void setProperty(const QString &); - QVariant value() const; - void setValue(const QVariant &); + QJSValue value() const; + void setValue(const QJSValue &); bool delayed() const; void setDelayed(bool); |