Skip to content

Instantly share code, notes, and snippets.

@cimm
Created March 27, 2015 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cimm/7c88dfccfc15840afa6a to your computer and use it in GitHub Desktop.
Save cimm/7c88dfccfc15840afa6a to your computer and use it in GitHub Desktop.
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