aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-01-18 12:13:23 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2021-01-18 13:20:12 +0100
commit65b88e61a5a67a0377b375b444fa4fb2a4c9f2b5 (patch)
treef16b86fb6edf20aa21a5e8eaef8222d498782f59 /src/qml
parent831efa14e91cfa358e57a32197578d41c2ae1b24 (diff)
QML engine: Fix writing function to property through alias
We special case writing functions to properties, only allowing assigning them to var properties and QJSValue properties. This would however break when aliases are involved. This commit fixes the issue by resolving the alias, and then checking and writing to the resolved property. Fixes: QTBUG-90373 Pick-to: 5.15 6.0 Change-Id: Ia09ebe92feeaf8359c99ff9aeadc676b9fcfaa07 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp
index 200ebfaffd..08d0c6f40e 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper.cpp
+++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp
@@ -463,7 +463,24 @@ void QObjectWrapper::setProperty(ExecutionEngine *engine, QObject *object, QQmlP
QV4::ScopedFunctionObject f(scope, value);
if (f) {
if (!f->isBinding()) {
- if (!property->isVarProperty() && property->propType().id() != qMetaTypeId<QJSValue>()) {
+ const bool isAliasToAllowed = [&]() {
+ if (property->isAlias()) {
+ const QQmlPropertyIndex originalIndex(property->coreIndex(), -1);
+ QObject *targetObject = nullptr;
+ QQmlPropertyIndex targetIndex;
+ QQmlPropertyPrivate::findAliasTarget(object, originalIndex, &targetObject, &targetIndex);
+ Q_ASSERT(targetObject);
+ QQmlPropertyCache *targetCache = QQmlData::get(targetObject)->propertyCache;
+ Q_ASSERT(targetCache);
+ QQmlPropertyData *targetProperty = targetCache->property(targetIndex.coreIndex());
+ object = targetObject;
+ property = targetProperty;
+ return targetProperty->isVarProperty() || targetProperty->propType() == QMetaType::fromType<QJSValue>();
+ } else {
+ return false;
+ }
+ }();
+ if (!isAliasToAllowed && !property->isVarProperty() && property->propType().id() != qMetaTypeId<QJSValue>()) {
// assigning a JS function to a non var or QJSValue property or is not allowed.
QString error = QLatin1String("Cannot assign JavaScript function to ");
if (!QMetaType(property->propType()).name())