I have this in a file named ChildItem.qml
:
Item{
property var childProperty
}
In another file named ParentItem.qml
, I create the parent item and try to bind the childProperty
to a property of the parent:
Item{
property ChildItem childItem: null
property var parentProperty
childItem.childProperty: parentProperty
}
In main.qml
I instantiate both objects and bind the parent's reference to the child:
ApplicationWindow{
ChildItem{
id: childID
}
ParentItem{
id: parentID
childItem: childID
}
}
This gives me a Cannot assign a value directly to a grouped property
error on the childItem.childProperty: parentProperty
line. I work around this by changing the parent as follows:
Item {
property ChildItem childItem: null
property var parentProperty
//childItem.childProperty: parentProperty
onParentPropertyChanged: childItem.childProperty = parentProperty
}
But this looks and feels very artificial. Are there better ways to do this or other suggestions to change the structure in another way?