The error occurs since the target of your alias declaration is not valid.
In QML you need to distinguish between Object and Component and what you have is not always transparent to the user.
Sometimes you can find in the documentation a property like sourceComponent
sourceComponent: Component
If you assign something to it, like:
sourceComponent: Item {}
the Item won't be instantiated. Instead a Component for this Item is implicitly created that can then be used to create Items. But since there is no instance of the Item yet, you also can't access any properties inside this non-existent Item.
Then in QML you have something called default property.
This property is the place to which all the subobjects are automatically assigned to.
Tab {
Item {}
}
and
Tab {
sourceComponent: Item {}
}
are equivalent. In most cases the default property is not of type Component, so the assigned thing is directly instantiated.
Now how to solve the problem? You might set active: true and read or write to theTab.item.theProperty using bindings, but you still can't alias to it since the syntax for alias only allows id.property and not id.someProperty.someNestedProperty.
But setting active: true implies that not only the properties are created, but all visual items, which is usually not desired. In my opinion, the best way is, to keep data and visual representation separated from each other:
You can have a ViewModel in which you have all the data stored, and you use the visual representation to bind to it. So the binding is initiated by the Tab to read (and possibly modify) the text. And your other object does the same, to the same property of the model object.
A model is not necessarily some sort of list of objects. It might be just one object with various properties for your view to display.
Itemis useless. I mean - it will create an alias, but only inside the loaded object. It won't help you to get the data to the outside. Usingactive:trueis enough to access the text viatab1.item.text. If you create a property (that can only be used to read from thetest-text) in theTabwriteproperty string tab1Text: (item ? item.text : '')- this will load the text, once theText {..}is loaded. - derM