From 84627464eb11ca1149d46946b12e3c82eb54a8bf Mon Sep 17 00:00:00 2001 From: Alberto Mardegan Date: Fri, 24 May 2013 10:46:39 +0300 Subject: 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 Reviewed-by: Alan Alpert --- .../qml/qqmlpropertymap/tst_qqmlpropertymap.cpp | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp') diff --git a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp index 327716f1b5..2b772ba9c4 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" -- cgit v1.2.3 From 843e222b17970c211dfab82215cf41adc4547ab5 Mon Sep 17 00:00:00 2001 From: Alberto Mardegan Date: Wed, 29 May 2013 11:29:52 +0300 Subject: QQmlPropertyCache: check methods before properties When creating the QQmlPropertyData, search within the methods list before searching for properties. The reason is that if the meta object is dynamic, looking up a property will always return a result (if the property doesn't exist, it will be created) and therefore all methods will be obscured. By swapping the search order, we eliminate this risk (methods are not dynamically added). Task-number: QTBUG-29836 Change-Id: Ie367f757c37ef4bc834a6c1c009f27bcf344fe76 Reviewed-by: Matthew Vogt Reviewed-by: Alan Alpert --- .../qml/qqmlpropertymap/tst_qqmlpropertymap.cpp | 32 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp') diff --git a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp index 2b772ba9c4..ca212d333b 100644 --- a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp +++ b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp @@ -67,6 +67,7 @@ private slots: void QTBUG_17868(); void metaObjectAccessibility(); void QTBUG_31226(); + void QTBUG_29836(); }; void tst_QQmlPropertyMap::insert() @@ -287,13 +288,17 @@ class MyEnhancedPropertyMap : public QQmlPropertyMap { Q_OBJECT public: - MyEnhancedPropertyMap() : QQmlPropertyMap(this, 0) {} + MyEnhancedPropertyMap() : QQmlPropertyMap(this, 0), m_testSlotCalled(false) {} + bool testSlotCalled() const { return m_testSlotCalled; } signals: void testSignal(); public slots: - void testSlot() {} + void testSlot() { m_testSlotCalled = true; } + +private: + bool m_testSlotCalled; }; void tst_QQmlPropertyMap::metaObjectAccessibility() @@ -341,6 +346,29 @@ void tst_QQmlPropertyMap::QTBUG_31226() } +void tst_QQmlPropertyMap::QTBUG_29836() +{ + MyEnhancedPropertyMap map; + QCOMPARE(map.testSlotCalled(), false); + + QQmlEngine engine; + QQmlContext context(&engine); + context.setContextProperty("enhancedMap", &map); + QQmlComponent c(&engine); + c.setData("import QtQuick 2.0\n" + "Item {\n" + " Timer { interval: 5; running: true; onTriggered: enhancedMap.testSlot() }\n" + "}", + QUrl()); + QObject *obj = c.create(&context); + QVERIFY(obj); + + QTRY_COMPARE(map.testSlotCalled(), true); + + delete obj; + +} + QTEST_MAIN(tst_QQmlPropertyMap) #include "tst_qqmlpropertymap.moc" -- cgit v1.2.3