Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
5.4.1
-
None
Description
This seems to be an issue with creating a qml object dynamically in javascript.
Basically, using a QML object as an argument in component.createComponent( parent,
) for a property which has a default set, fails.
To display this issue, the test code includes a qml object, ItemParent.qml, which has a property of type ItemProperty that is set to a default itemProperty.
The property item has a bool property within it (testProperty) defaulted to false.
In the failing case, a property item is created dynamically using Qt.createObject with it's testProperty set to true.
var component = Qt.createComponent( "ItemProperty" );
var myProperty = component.createObject( null,
);
-> qml: myProperty.testProperty: true
Then an ItemParent is created dynamically using Qt.createObject with the existing ItemProperty (with its true value) as an argument.
var parentComponent = Qt.createComponent( "ItemParent.qml" );
var myParent = parentComponent.createObject( null,
);
The property assignment fails in the first case. Instead the default version of itemProperty is created and set in the ItemParent, and the argument passed into the component.createObject is ignored.
-> qml: myParent: myParent.itemProperty.testProperty: false
However, if I repeat the sequence with a derived object of ItemProperty (ItemPropertyDerived), the assignment is successful.
var component = Qt.createComponent( "ItemPropertyDerived" );
var myProperty = component.createObject( null,
);
-> qml: myProperty: myProperty.testProperty: true
Then an ItemParent is created dynamically using Qt.createObject with the existing ItemProperty (with its true value) as an argument.
var parentComponent = Qt.createComponent( "ItemParent.qml" );
var myParent = parentComponent.createObject( null,
);
The property assignment is successful
-> qml: myParent: myParent.itemProperty.testProperty: true
Full Output:
qml: -------------------------------------
qml: ItemProperty onCompleted: ItemProperty_QMLTYPE_149(0xd8848d0) testProperty: true
qml: myProperty: ItemProperty_QMLTYPE_149(0xd8848d0) myProperty.testProperty: true
qml: ItemParent onCompleted: ItemParent_QMLTYPE_151(0x1503a3d8) itemProperty: ItemProperty_QMLTYPE_150(0x1503a3a8) itemProperty.testProperty: false
qml: ItemProperty onCompleted: ItemProperty_QMLTYPE_150(0x1503a3a8) testProperty: false
qml: myParent: ItemParent_QMLTYPE_151(0x1503a3d8) myParent.itemProperty: ItemProperty_QMLTYPE_150(0x1503a3a8) myParent.itemProperty.testProperty: false
qml: -------------------------------------
qml: -------------------------------------
qml: ItemProperty onCompleted: ItemPropertyDerived_QMLTYPE_152(0x1503a7e0) testProperty: true
qml: ItemPropertyDerived onCompleted: ItemPropertyDerived_QMLTYPE_152(0x1503a7e0) testProperty: true
qml: myProperty: ItemPropertyDerived_QMLTYPE_152(0x1503a7e0) myProperty.testProperty: true
qml: ItemParent: onItemPropertyChanged: ItemParent_QMLTYPE_151(0x1503ad38) itemProperty: ItemPropertyDerived_QMLTYPE_152(0x1503a7e0) itemProperty.testProperty: true
qml: ItemParent onCompleted: ItemParent_QMLTYPE_151(0x1503ad38) itemProperty: ItemPropertyDerived_QMLTYPE_152(0x1503a7e0) itemProperty.testProperty: true
qml: myParent: ItemParent_QMLTYPE_151(0x1503ad38) myParent.itemProperty: ItemPropertyDerived_QMLTYPE_152(0x1503a7e0) myParent.itemProperty.testProperty: true
qml: -------------------------------------
Attachments
Issue Links
- relates to
-
QTBUG-114403 No way to set initial properties in QtQuick
- Reported