Well, in the second scenario the button will not be visible. It will exist as a property, but since it is not a child in the object tree it will not be displayed. So it is pretty much useless to have a visual element as a property.
There is no parent/child relation between an object and its properties. It exists only for QObject
and derived trees, which are a fundamental concept to structuring Qt applications. Also, this implies that you can't have something like an int
as a child, it can only be a property. Properties imply data, not structure.
As cmannett85 noted, children will also be interfaced as a list property depending on their type, but in QML you should rarely be concerned with that, if ever... But while children are interfaced as properties, properties do not get the complimentary treatment.
Note that you can have it both ways.
Rectangle{
property alias myButton: button
Button {
id: button
}
}
This way the button will be visible, and you will still have a reference to it as a property if you want to access it from outside the current QML file, which does not work with id
s - they are valid only for the QML file they are in. Dynamic scoping works for properties, but not for ids.