From 7eb0aeab97135e24efbc1c9876c0b30becf44fd5 Mon Sep 17 00:00:00 2001 From: Alberto Mardegan Date: Fri, 24 May 2013 10:46:39 +0300 Subject: [PATCH] Fallback to QMetaObject for properties not in QQmlPropertyCache QQmlOpenMetaObject does not update the QQmlPropertyCache when new properties are added, meaning that the QQmlPropertyCache might not contain all of the dynamic properties of an object. Therefore, make QQmlPropertyCache fallback to reading the QMetaObject when a property is not found. Task-number: QTBUG-31226 Change-Id: I760aaa155b1952f6f52ab9ce173fb9547f8e34a6 --- src/qml/qml/qqmlpropertycache.cpp | 3 ++- src/qml/qml/v8/qv8qobjectwrapper.cpp | 2 +- .../qml/qqmlpropertymap/tst_qqmlpropertymap.cpp | 29 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp index e1aa310..7a65369 100644 --- a/src/qml/qml/qqmlpropertycache.cpp +++ b/src/qml/qml/qqmlpropertycache.cpp @@ -1395,7 +1395,8 @@ qQmlPropertyCacheProperty(QQmlEngine *engine, QObject *obj, const T &name, if (cache) { rv = cache->property(name, obj, context); - } else { + } + if (!rv) { local = qQmlPropertyCacheCreate(obj->metaObject(), qQmlPropertyCacheToString(name)); if (local.isValid()) rv = &local; diff --git a/src/qml/qml/v8/qv8qobjectwrapper.cpp b/src/qml/qml/v8/qv8qobjectwrapper.cpp index 4539401..580d241 100644 --- a/src/qml/qml/v8/qv8qobjectwrapper.cpp +++ b/src/qml/qml/v8/qv8qobjectwrapper.cpp @@ -524,7 +524,7 @@ v8::Handle QV8QObjectWrapper::GetProperty(QV8Engine *engine, QObject QQmlData *ddata = QQmlData::get(object, false); if (ddata && ddata->propertyCache) result = ddata->propertyCache->property(property, object, context); - else + if (!result) result = QQmlPropertyCache::property(engine->engine(), object, property, context, local); } diff --git a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp index 327716f..2b772ba 100644 --- a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp +++ b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp @@ -66,6 +66,7 @@ private slots: void crashBug(); void QTBUG_17868(); void metaObjectAccessibility(); + void QTBUG_31226(); }; void tst_QQmlPropertyMap::insert() @@ -312,6 +313,34 @@ void tst_QQmlPropertyMap::metaObjectAccessibility() QVERIFY2(messageHandler.messages().isEmpty(), qPrintable(messageHandler.messageString())); } +void tst_QQmlPropertyMap::QTBUG_31226() +{ + /* Instantiate a property map from QML, and verify that property changes + * made from C++ are visible from QML */ + QQmlEngine engine; + QQmlContext context(&engine); + qmlRegisterType("QTBUG_31226", 1, 0, "PropertyMap"); + QQmlComponent c(&engine); + c.setData("import QtQuick 2.0\nimport QTBUG_31226 1.0\n" + "Item {\n" + " property string myProp\n" + " PropertyMap { id: qmlPropertyMap; objectName: \"qmlPropertyMap\" }\n" + " Timer { interval: 5; running: true; onTriggered: { myProp = qmlPropertyMap.greeting; } }\n" + "}", + QUrl()); + QObject *obj = c.create(&context); + QVERIFY(obj); + + QQmlPropertyMap *qmlPropertyMap = obj->findChild(QString("qmlPropertyMap")); + QVERIFY(qmlPropertyMap); + + qmlPropertyMap->insert("greeting", QString("Hello world!")); + QTRY_COMPARE(obj->property("myProp").toString(), QString("Hello world!")); + + delete obj; + +} + QTEST_MAIN(tst_QQmlPropertyMap) #include "tst_qqmlpropertymap.moc" -- 1.8.1.2