Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML XmlListModel more than one element
Qt 6.12 LTS is out! See what's new in the release blog

QML XmlListModel more than one element

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 853 Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Helo :)

    I am trying to get xml data into a QML XmlListModel, I've gotten most of it working now but bit lost with the last part to get multiple category streams.

    The xml itself looks like this:

    @<root>
    

    <fullscreen>false</fullscreen>
    <aspectratio>default</aspectratio>
    <audiodelay>0</audiodelay>
    <apiversion>3</apiversion>
    <currentplid>4</currentplid>
    <time>1</time>
    <volume>0</volume>
    <length>9907</length>
    <random>false</random>
    <rate>1</rate>
    <state>paused</state>
    <loop>false</loop>
    <version>2.1.5 Rincewind</version>
    <position>0.00018763827392831</position>
    <repeat>false</repeat>
    <subtitledelay>0</subtitledelay>
    <category name="meta">
    <info name="title">
    The Movie
    </info>
    <info name="filename">
    The Movie
    </info>
    </category>
    <category name="Stream 0">
    <info name="Type">Video</info>
    <info name="Frame rate">23.976215</info>
    <info name="Decoded format">Planar 4:2:0 YUV</info>
    <info name="Codec">H264 - MPEG-4 AVC (part 10) (avc1)</info>
    <info name="Language">English</info>
    <info name="Resolution">1024x542</info>
    </category>
    <category name="Stream 1">
    <info name="Bitrate">384 kb/s</info>
    <info name="Type">Audio</info>
    <info name="Channels">3F2R/LFE</info>
    <info name="Sample rate">48000 Hz</info>
    <info name="Language">Russian</info>
    <info name="Codec">A52 Audio (aka AC3) (a52 )</info>
    </category><category name="Stream 6"><info name="Description">Full</info>
    <info name="Type">Subtitle</info>
    <info name="Language">English</info>
    <info name="Codec">Text subtitles with various tags (subt)</info>
    </category><category name="Stream 3"><info name="Description">Forced</info>
    <info name="Type">Subtitle</info>
    <info name="Language">Russian</info>
    <info name="Codec">Text subtitles with various tags (subt)</info>
    </category>
    <category name="Stream 7">
    <info name="Description">SDH</info>
    <info name="Type">Subtitle</info>
    <info name="Language">English</info>
    <info name="Codec">Text subtitles with various tags (subt)</info>
    </category><category name="Stream 5"><info name="Description">Forced</info>
    <info name="Type">Subtitle</info>
    <info name="Language">English</info>
    <info name="Codec">Text subtitles with various tags (subt)</info>
    </category>
    <category name="Stream 4">
    <info name="Description">Full</info>
    <info name="Type">Subtitle</info>
    <info name="Language">Russian</info>
    <info name="Codec">Text subtitles with various tags (subt)</info>
    </category>
    <category name="Stream 2">
    <info name="Codec">A52 Audio (aka AC3) (a52 )</info>
    <info name="Type">Audio</info>
    <info name="Language">English</info>
    <info name="Sample rate">48000 Hz</info>
    </category>
    </information>
    </root>
    @

    And for it I got this xmllistmodel working to get the data out:

    @ XmlListModel{
        id: xmlModel
        query: "/root"
        XmlRole{ name: "fullscreen"; query: "fullscreen/string()"}
        XmlRole{ name: "aspectratio"; query: "aspectratio/string()"}
        XmlRole{ name: "audiodelay"; query: "audiodelay/string()"}
        XmlRole{ name: "currentplid"; query: "currentplid/string()"}
        XmlRole{ name: "time"; query: "time/string()"}
        XmlRole{ name: "volume"; query: "volume/string()"}
        XmlRole{ name: "length"; query: "length/string()"}
        XmlRole{ name: "random"; query: "random/string()"}
        XmlRole{ name: "rate"; query: "rate/string()"}
        XmlRole{ name: "state"; query: "state/string()"}
        XmlRole{ name: "loop"; query: "loop/string()"}
        XmlRole{ name: "repeat"; query: "repeat/string()"}
        XmlRole{ name: "subtitledelay"; query: "subtitledelay/string()"}
    
        XmlRole{ name: "artist"; query: "information/category/info[@name='artist']/string()"}
        XmlRole{ name: "album"; query: "information/category/info[@name='album']/string()"}
        XmlRole{ name: "filename"; query: "information/category/info[@name='filename']/string()"}
    
        //Stream 0 is hard-coded :(
        XmlRole{ name: "type"; query: "information/category[@name='Stream 0']/info[@name='Type']/string()"}
    }
    

    @

    All above information is fine but what I can't seem to get properly is the multiple stream information. As depending on the file there could only be 2 streams or even 10 if user has more audio tracks or subtitles.
    The last line in the xmllistmodel I can lookup the type of the stream 0 but then it needs to be hard-coded.
    What I am trying to find is the stream number what type it is.

    Is there any way to get this information from xml using qml for all of the streams?

    Thanks :)

    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
    • Unsolved