Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nested elements in a QML XmlListModel
import QtQuick 2.0
ListView {
property int parentIndex
height: 20
model: MyXmlListModel{
query: "/papers/paper["+parentIndex+"]/authors/author"
}
delegate: Text{ text: parentIndex + " - " + author }
}
import QtQuick 2.0
import QtQuick.XmlListModel 2.0
Rectangle {
width: 300
height: 400
XmlListModel {
id: xmlModel
source: "http://example.com/papers.xml"
query: "/papers/paper/authors/author"
XmlRole { name: "author"; query: "@name/string()" }
}
ListView {
anchors.fill: root
spacing: 20
model: xmlModel.count
delegate: AuthorDelegate {
parentIndex: index
}
}
}
<papers>
<paper id="1">
<authors>
<author name="Author 1.1" />
<author name="Author 1.2" />
</authors>
</paper>
<paper id="2">
<authors>
<author name="Author 2.1" />
</authors>
</paper>
<paper id="3">
<authors>
<author name="Author 3.1" />
<author name="Author 3.2" />
</authors>
</paper>
</papers>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.