Allow aliases to QVariant properties
authorAaron Kennedy <aaron.kennedy@nokia.com>
Wed, 9 Nov 2011 14:13:41 +0000 (14:13 +0000)
committerQt by Nokia <qt-info@nokia.com>
Wed, 16 Nov 2011 12:04:50 +0000 (13:04 +0100)
Task-number: QTBUG-22464
Change-Id: I449d4fc709d34a69116258660d721596cd9b778b
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
src/declarative/qml/qdeclarativecompiler.cpp
tests/auto/declarative/qdeclarativeecmascript/data/qtbug_22464.qml [new file with mode: 0644]
tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp

index fb98a8c..d3069ec 100644 (file)
@@ -3112,7 +3112,8 @@ bool QDeclarativeCompiler::compileAlias(QFastMetaBuilder &builder,
         writable = aliasProperty.isWritable() && !prop.isReadOnly;
         resettable = aliasProperty.isResettable() && !prop.isReadOnly;
 
-        if (aliasProperty.type() < QVariant::UserType)
+        if (aliasProperty.type() < QVariant::UserType ||
+            aliasProperty.type() == QVariant::LastType /* for QVariant */ )
             type = aliasProperty.type();
 
         if (alias.count() == 3) {
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_22464.qml b/tests/auto/declarative/qdeclarativeecmascript/data/qtbug_22464.qml
new file mode 100644 (file)
index 0000000..19f2673
--- /dev/null
@@ -0,0 +1,15 @@
+import QtQuick 2.0
+
+QtObject {
+    property alias value: inner.value
+    property bool test: false
+
+    property variant dummy: QtObject {
+        id: inner
+        property variant value: Qt.rgba(1, 1, 0, 1);
+    }
+
+    Component.onCompleted: {
+        test = (value == Qt.rgba(1, 1, 0, 1));
+    }
+}
index 11e33be..e784ffb 100644 (file)
@@ -177,7 +177,7 @@ private slots:
     void sequenceConversionThreads();
     void sequenceConversionBindings();
     void sequenceConversionCopy();
-
+    void qtbug_22464();
     void bug1();
     void bug2();
     void dynamicCreationCrash();
@@ -1643,6 +1643,18 @@ void tst_qdeclarativeecmascript::undefinedResetsProperty()
     }
 }
 
+// Aliases to variant properties should work
+void tst_qdeclarativeecmascript::qtbug_22464()
+{
+    QDeclarativeComponent component(&engine, TEST_FILE("qtbug_22464.qml"));
+    QObject *object = component.create();
+    QVERIFY(object != 0);
+
+    QCOMPARE(object->property("test").toBool(), true);
+
+    delete object;
+}
+
 // QTBUG-6781
 void tst_qdeclarativeecmascript::bug1()
 {