[Solved] Filtering data in XMLListModel

  • Hello,

    I want to know how can we filter data in XMLListModel.

    Let's say I've following XML file:


    and I want to fetch all file names which have ".jpeg" extension. XPath defines contains() function to compare strings; is it supported by QML ?

  • I think so yes, but why don't you just try and see?

  • Hi,

    Thanks for your reply. I was making a mistake while writing XPath predicate. Following model works for me now.

    @XmlListModel {
    source: "mysource.xml"
    query: "/root/file[contains(.,'jpeg')]"

    XmlRole { name: "name"; query: "string()" }


  • Glad that it works for you, and thanks for reporting back!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.