Reputation: 2432
When declaring custom QML element in separate file (to be reusable across project(s)), which option is better, to declare it as Item
or as Component
and what are pros and cons for them?
Upvotes: 0
Views: 1162
Reputation: 50540
Once I had the same doubts and the following example helped me. I put it there, hoping it can help you.
Here is the component defined in a file somewhere:
// FooBar.qml
// import whatever.you.need
Rectangle { }
Here a possible use as involved as main item of another component definition:
// ...
Component {
id: myFooBar
FooBar { }
}
// ...
Well, what about if the first one was as it follows?
// FooBar.qml
// import whatever.you.need
Component {
Rectangle { }
}
Actually it doesn't make much sense, besides the official documentation. Does it?
That's why I've never tried it... But I've also read the documentation, of course, as kindly pointed out by someone else!! It's far more helpful. :-)
Upvotes: 1