From 5adb406bddd8419c2987cec48eb86a0d4ca0260a Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 11 Dec 2014 21:18:00 -0600 Subject: [PATCH] Fix QQmlProperty to work correctly with deeply nested objects. Don't keep reusing the top-level object to look up nested properties. This allows code such as the following to work correctly: PropertyChanges { target: myObject textChild.font.pixelSize: 24 } Change-Id: I39e52dbc20d2409fc756a36e668fcf664eb1905f Reviewed-by: Brett Stottlemyer Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlproperty.cpp | 2 +- tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp index 0ee8f94..b852083 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -276,7 +276,7 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name) QQmlPropertyData local; QQmlPropertyData *property = - QQmlPropertyCache::property(engine, obj, pathName, context, local); + QQmlPropertyCache::property(engine, currentObject, pathName, context, local); if (!property) return; // Not a property if (property->isFunction()) diff --git a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp index 62ccec5..ed09e6d 100644 --- a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp +++ b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp @@ -47,8 +47,12 @@ class MyQmlObject : public QObject { Q_OBJECT + Q_PROPERTY(QPoint pointProperty MEMBER m_point) public: MyQmlObject(QObject *parent = 0) : QObject(parent) {} + +private: + QPoint m_point; }; QML_DECLARE_TYPE(MyQmlObject); @@ -141,6 +145,7 @@ private slots: void assignEmptyVariantMap(); void warnOnInvalidBinding(); void registeredCompositeTypeProperty(); + void deeplyNestedObject(); void copy(); private: @@ -1938,6 +1943,16 @@ void tst_qqmlproperty::warnOnInvalidBinding() delete obj; } +void tst_qqmlproperty::deeplyNestedObject() +{ + PropertyObject o; + QQmlProperty p(&o, "qmlObject.pointProperty.x"); + QCOMPARE(p.isValid(), true); + + p.write(14); + QCOMPARE(p.read(), QVariant(14)); +} + void tst_qqmlproperty::initTestCase() { QQmlDataTest::initTestCase(); -- 2.7.4