Why wrap an inline delegate in a Component?
-
In some places in the Qt documentation I see constructions like this one (taken from the "QML Scope":http://doc-snapshot.qt-project.org/4.8/qdeclarativescope.html page):
@
PathView {
delegate: Component {
Rectangle {
id: root
Image {
scale: root.PathView.scale
}
}
}
}
@My question is, what is the use of the Component element encapsulating the Rectangle element here? Why not use the Rectangle element as delegate directly, i.e.:
@
PathView {
delegate: Rectangle {
id: root
Image {
scale: root.PathView.scale
}
}
}
@Is there any difference between those two approaches, and if so, when should I chose the first and when the second?
-
As per the previous comment, there is no difference. If the required type is 'Component' but the provided type is not a Component, a Component is created automatically for your convenience. I'd stick with the second just because its nicer to read and less to type.