Nominate our 2022 Qt Champions!

How to use XML source as a data type, not a list model?

  • Many times XML source we got is more like a single data type, like this:

    But XmlListModel is used for XML source which is a collection of data types:

    XmlListModel is great for representing data collections, but is there a XmlData like this:
    @XmlData {
    id: data
    source: ""

     XmlRole { name: "name"; query: "name/string()" }
     XmlRole { name: "age"; query: "age/int()" }


    So I can use it like a normal object:
    @Text {

    Is there a solution for this in QML? I know I can use a C++ object to do it, but it requires quite a lot of work and is less clean.

  • Hi,

    There isn't an element like this yet, but it is one we'd like to add. For reference, the task for this is "QTBUG-12953":

    As a workaround, you may be able to use XmlListModel with "get": to work with the data as though it were a "list of one element".


Log in to reply