summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/qml/qdeclarativecomponent.cpp17
-rw-r--r--tests/auto/declarative/qdeclarativecomponent/data/createObjectWithScript.qml9
-rw-r--r--tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp3
3 files changed, 23 insertions, 6 deletions
diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp
index 06bf3fd..5840f70 100644
--- a/src/declarative/qml/qdeclarativecomponent.cpp
+++ b/src/declarative/qml/qdeclarativecomponent.cpp
@@ -715,10 +715,21 @@ QScriptValue QDeclarativeComponentPrivate::createObject(QObject *publicParent, c
QScriptValueIterator it(valuemap);
while (it.hasNext()) {
it.next();
- if (it.value().isFunction()) { // To allow property binding from javascript to work
- newObject.setProperty(it.name(), it.value());
+ QScriptValue prop = newObject;
+ QString propName = it.name();
+ int index = propName.indexOf(QLatin1Char('.'));
+ if (index > 0) {
+ QString subProp = propName;
+ int lastIndex = 0;
+ while (index > 0) {
+ subProp = propName.mid(lastIndex, index - lastIndex);
+ prop = prop.property(subProp);
+ lastIndex = index + 1;
+ index = propName.indexOf(QLatin1Char('.'), index + 1);
+ }
+ prop.setProperty(propName.mid(propName.lastIndexOf(QLatin1Char('.')) + 1), it.value());
} else {
- QDeclarativeProperty::write(ret,it.name(),it.value().toVariant());
+ newObject.setProperty(propName, it.value());
}
}
}
diff --git a/tests/auto/declarative/qdeclarativecomponent/data/createObjectWithScript.qml b/tests/auto/declarative/qdeclarativecomponent/data/createObjectWithScript.qml
index 2ce76ed..0da3bda 100644
--- a/tests/auto/declarative/qdeclarativecomponent/data/createObjectWithScript.qml
+++ b/tests/auto/declarative/qdeclarativecomponent/data/createObjectWithScript.qml
@@ -8,7 +8,12 @@ Item{
property QtObject bindingTestObject : null
property QtObject bindingThisTestObject : null
- Component{id: a; Rectangle{} }
+ Component{
+ id: a
+ Rectangle {
+ property Rectangle innerRect: Rectangle { border.width: 20 }
+ }
+ }
Component{
id: b
Item{
@@ -29,7 +34,7 @@ Item{
}
Component.onCompleted: {
- root.declarativerectangle = a.createObject(root, {"x":17,"y":17, "color":"white", "border.width":3});
+ root.declarativerectangle = a.createObject(root, {"x":17,"y":17, "color":"white", "border.width":3, "innerRect.border.width": 20});
root.declarativeitem = b.createObject(root, {"x":17,"y":17,"testBool":true,"testInt":17,"testObject":root});
root.bindingTestObject = c.createObject(root, {'testValue': (function(){return width * 3}) }) // use root.width
diff --git a/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp b/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp
index 7b7b392..4340fce 100644
--- a/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp
+++ b/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp
@@ -137,12 +137,13 @@ void tst_qdeclarativecomponent::qmlCreateObjectWithProperties()
QCOMPARE(testObject1->property("y").value<int>(), 17);
QCOMPARE(testObject1->property("color").value<QColor>(), QColor(255,255,255));
QCOMPARE(QDeclarativeProperty::read(testObject1,"border.width").toInt(), 3);
+ QCOMPARE(QDeclarativeProperty::read(testObject1,"innerRect.border.width").toInt(), 20);
delete testObject1;
QObject *testObject2 = object->property("declarativeitem").value<QObject*>();
QVERIFY(testObject2);
QVERIFY(testObject2->parent() == object);
- QCOMPARE(testObject2->metaObject()->className(), "QDeclarativeItem_QML_2");
+ //QCOMPARE(testObject2->metaObject()->className(), "QDeclarativeItem_QML_2");
QCOMPARE(testObject2->property("x").value<int>(), 17);
QCOMPARE(testObject2->property("y").value<int>(), 17);
QCOMPARE(testObject2->property("testBool").value<bool>(), true);