From a824a6f060ec3a0000d7349649a3ab9e0570ecaa Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 5 Oct 2022 17:02:03 +0200 Subject: Recursively write back value types and sequences Both types have functionality to write themselves back to the properties they were loaded from on change, but so far we could not nest those writes. [ChangeLog][QtQml] You can now assign to properties of nested value types and to elements of containers from QML functions. You cannot, however, take references of such values and elements. This is in contrast to non-nested value types and the containers themselves. However, passing references of value types and containers around generally leads to very confusing effects. Don't do this. Fixes: QTBUG-99766 Change-Id: I74cb89e5c3d733b0b61e42969d617b2ecc1562f4 Reviewed-by: Fabian Kosmale --- src/qml/jsruntime/qv4qmlcontext.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/qml/jsruntime/qv4qmlcontext.cpp') diff --git a/src/qml/jsruntime/qv4qmlcontext.cpp b/src/qml/jsruntime/qv4qmlcontext.cpp index 1a1636a988..1cabf7c6c2 100644 --- a/src/qml/jsruntime/qv4qmlcontext.cpp +++ b/src/qml/jsruntime/qv4qmlcontext.cpp @@ -277,14 +277,16 @@ ReturnedValue QQmlContextWrapper::getPropertyAndBase(const QQmlContextWrapper *r bool hasProp = false; const QQmlPropertyData *propertyData = nullptr; + + QV4::ScopedObject wrapper(scope, QV4::QObjectWrapper::wrap(v4, scopeObject)); QV4::ScopedValue result(scope, QV4::QObjectWrapper::getQmlProperty( - v4, context, scopeObject, name, getQmlPropertyFlags(lookup), - &hasProp, &propertyData)); + v4, context, wrapper->d(), scopeObject, name, + getQmlPropertyFlags(lookup), &hasProp, &propertyData)); if (hasProp) { if (hasProperty) *hasProperty = true; if (base) - *base = QV4::QObjectWrapper::wrap(v4, scopeObject); + *base = wrapper; if (lookup && propertyData) { QQmlData *ddata = QQmlData::get(scopeObject, false); @@ -318,14 +320,15 @@ ReturnedValue QQmlContextWrapper::getPropertyAndBase(const QQmlContextWrapper *r if (QObject *contextObject = context->contextObject()) { bool hasProp = false; const QQmlPropertyData *propertyData = nullptr; + QV4::ScopedObject wrapper(scope, QV4::QObjectWrapper::wrap(v4, contextObject)); result = QV4::QObjectWrapper::getQmlProperty( - v4, context, contextObject, name, getQmlPropertyFlags(lookup), + v4, context, wrapper->d(), contextObject, name, getQmlPropertyFlags(lookup), &hasProp, &propertyData); if (hasProp) { if (hasProperty) *hasProperty = true; if (base) - *base = QV4::QObjectWrapper::wrap(v4, contextObject); + *base = wrapper; if (propertyData) { if (lookup) { @@ -750,11 +753,13 @@ ReturnedValue QQmlContextWrapper::lookupInParentContextHierarchy(Lookup *l, Exec // Search context object if (QObject *contextObject = context->contextObject()) { bool hasProp = false; + QV4::ScopedObject wrapper(scope, QV4::QObjectWrapper::wrap(engine, contextObject)); result = QV4::QObjectWrapper::getQmlProperty( - engine, context, contextObject, name, getQmlPropertyFlags(l), &hasProp); + engine, context, wrapper->d(), contextObject, name, getQmlPropertyFlags(l), + &hasProp); if (hasProp) { if (base) - *base = QV4::QObjectWrapper::wrap(engine, contextObject); + *base = wrapper; return result->asReturnedValue(); } -- cgit v1.2.3