I am new to QML and would like to understand how object creation works when splitting code over different files (as it feels like a good code practice).
I know I can call property of an item within the same file:
// MyItem.qml
Item {
id: myItem
property string name: "Myself"
onClicked: {
console.log(myItem.name)
}
}
but how do I create an instance of the same item in a different file?
// Main.qml
Button {
onClicked: {
console.log(myItem.name)
}
}
Throws a ReferenceError: name is not defined error which I suppose means: "can not call property name of an undefined object".
Is this common practice in QML (don't see a lot of examples doing this) or does everyone simply put everything in the same file?