Hi,
as I’m a totaly unexperienced QML scripter, I need to know some general things about scopes.
Let’s say I have a main.qml (which is loaded in the c++ source file) and about 5 qml components (CompA.qml, CompB.qml, CompC.qml, CompD.qml, CompE.qml).
They are all stored in the same directory as main.qml.
When I try to use a component in my main.qml, I’m wondering why I don’t even have to import/include the component file (e.g. CompA.qml). Instead, I can simply use it like that:
//main.qml
CompA
{
//...
}
Question 1:
Is there a general rule how QtCreator automatically inlcudes QML component files??
Question 2:
Let’s say, I create 5 instances of CompA in my main.qml, and my CompA has a pre-defined id property. Then I would have 5 objects with the same ID in my main.qml, what should result in an error, right? Instead, I can do that without any problems. So how is the ID – Scope relation handled in QML projects??
Question 3:
Let’s say, I create 5 instances of CompA with a resulting 5x identically ID, how can I access the component using its ID when it is no longer unique?? (This question links to Question 2 again)?
Question 4:
How can I create objects/components that are accessable from two different qml files, e.g. from main.qml and from CompA.qml? Example:
CompA is a button with a background image. The background image source is a property binding to an Item that should be also accessable from main.qml, because there I want to change the source url and so every button (CompA) should apply these changes immediatelly.
I don’t know how to realize that, because I don’t know how to create such an Item that is accessable from main.qml and from CompA.qml (I mean, I can’t put the Item into the CompA.qml right? Because then it would be created for each CompA instance, right?)
I would really appreciate it to get some help from you :-)
Thank you in anticipation!
↧