Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Parsing local XML file to ListModel via XmlListModel
Qt 6.11 is out! See what's new in the release blog

Parsing local XML file to ListModel via XmlListModel

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 347 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stefan0893
    wrote on last edited by stefan0893
    #1

    Hello,
    I have a problem with the XmlListModel object. I tried to read a dummy.xml input file, which is strucutred something like this:

    Dummy.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <dummyroot>
    <item>
    <title>stuff 1</title>
    <date>Sat, 07 Sep 2010 10:00:01 GMT</date>
    </item>
    <item>
    <title>stuff 2</title>
    <date>Sat, 07 Sep 2010 15:35:01 GMT</date>
    </item>
    </dummyroot>

    My QML code looks something like this:

    main.qml

    XmlListModel {
        id: xmlModel
        source: "file://C:/...../Dummy.xml"
        query: "/dummyroot/item"
        XmlRole { name: "title"; query: "title/string()"}
        XmlRole { name: "date"; query: "date/string()" }
    }
    Component{
        id:xmlDelegate
        Row{
            Text{text:title;color:"white"}
            Text{text:date;color:"white"}
        }
    }
    

    with an additional ListView added to show the data. Sadly it wont show any data, nor print model inputs via print(xmlModel.get(0).title)...
    I furthermore tested the loading state functionality via a function which looks like this:
    function do_xmldata_work()
    {
    console.log("do_xmldata_work begin>: ")
    while(xmlModel.status != XmlListModel.Ready)
    console.log("loading xml file: " + xmlModel.status + " error Message" + xmlModel.errorString())
    console.log("loading xml file: " + xmlModel.status + " || finished")
    }

    The status is 1 or finished, but the ListView stays empty.
    print(xmlModel.get(0).title) returns TypeError: Cannot read property 'title' of undefined

    Any help would be much appreciated!
    Thanks in advance!

    Stefan

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved