When I define a Component in QML I can define a alias property to expose properties of QtObjects that are otherwise hidden by the Components root.
Especially interesting is the default property alias to build powerful reusable and adaptable Components. But there is no generic way to have alter the nameresolution, which is bad for properties and signals.
Example: MyComp1.qml
Item { id: rootItem default property alias content: childItem.data signal sig() Item { id: childItem } } main.qml
MyComp { id: myObj signal sig1() onSig1: console.log('here') Button { id: button onClicked: { parent.sig() parent.sig1() } } } Here button is now a child of childItem, but both signals: sig() and sig1() are defined in rootItem, which leads to an error. To the user of of my nicely designed Component it is not transparent. He would need to look in the code of the Component to realize, why the buttons parent is not myObj/rootItem but in fact of childItem. This might lead to bugs.
Therefore I am looking for a way to prevent it.
For signal sig() this would be possible by the modifying the MyComp and manually forward the signal from childItem to rootItem:
Item { id: rootItem default property alias content: childItem.data signal sig() Item { id: childItem signal sig() onSig: rootItem.sig() } } But is there a way to shortcut this, so that the user does not need to us myObj.sig1() but might use parent.sig1().
Same goes for properties, that are added uppon instantiation:
MyComp { signal sig1() property int num: 5 Button { text: parent.num // <--- Error } } It would be nice, if the properties and signals defined uppon instantiation would be available as parent.propertyName to the Objects added by a default-property aswell, I think. Is there a way (to maybe hack this)?