From bf3dfe64068d76f98a2176530e1158d5143e09b2 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 2 Jan 2014 12:17:31 +0100 Subject: Fix property access to QQmlPropertyMap objects when addressed via id Property access to id objects is optimized at compile time, but we cannot do that for QQmlPropertyMap instances (or generally fully dynamic types). This issue was a regression against Qt 5.1 Task-number: QTBUG-35906 Change-Id: I759a1a899f6a3a1f6466282f455b289ad7451086 Reviewed-by: Albert Astals Cid Reviewed-by: Lars Knoll --- .../qml/qqmlpropertymap/tst_qqmlpropertymap.cpp | 29 ++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp index 17f54508a3..62b64a3ef1 100644 --- a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp +++ b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp @@ -72,6 +72,7 @@ private slots: void QTBUG_29836(); void QTBUG_35233(); void disallowExtending(); + void QTBUG_35906(); }; class LazyPropertyMap : public QQmlPropertyMap, public QQmlParserStatus @@ -79,7 +80,7 @@ class LazyPropertyMap : public QQmlPropertyMap, public QQmlParserStatus Q_OBJECT Q_INTERFACES(QQmlParserStatus) - Q_PROPERTY(int someFixedProperty READ someFixedProperty WRITE setSomeFixedProperty) + Q_PROPERTY(int someFixedProperty READ someFixedProperty WRITE setSomeFixedProperty NOTIFY someFixedPropertyChanged) public: LazyPropertyMap() : QQmlPropertyMap(this, /*parent*/0) @@ -92,7 +93,10 @@ public: } int someFixedProperty() const { return value; } - void setSomeFixedProperty(int v) { value = v; } + void setSomeFixedProperty(int v) { value = v; emit someFixedPropertyChanged(); } + +signals: + void someFixedPropertyChanged(); private: int value; @@ -450,6 +454,27 @@ void tst_QQmlPropertyMap::disallowExtending() QCOMPARE(component.errors().at(0).toString(), QStringLiteral(": Fully dynamic types cannot declare new properties.")); } +void tst_QQmlPropertyMap::QTBUG_35906() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData("import QtQml 2.0\n" + "import QTBUG_35233 1.0\n" + "QtObject {\n" + " property int testValue: mapById.someFixedProperty\n" + "\n" + " property QtObject maProperty: LazyPropertyMap {\n" + " id: mapById\n" + " someFixedProperty: 42\n" + " }\n" + "}\n", QUrl()); + QScopedPointer obj(component.create()); + QVERIFY(!obj.isNull()); + QVariant value = obj->property("testValue"); + QVERIFY(value.type() == QVariant::Int); + QCOMPARE(value.toInt(), 42); +} + QTEST_MAIN(tst_QQmlPropertyMap) #include "tst_qqmlpropertymap.moc" -- cgit v1.2.3