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. [Solved] Filtering data in XMLListModel
Forum Updated to NodeBB v4.3 + New Features

[Solved] Filtering data in XMLListModel

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 3.8k 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.
  • S Offline
    S Offline
    situ117
    wrote on last edited by
    #1

    Hello,

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

    Let's say I've following XML file:

    @<root>
    <file>image1.jpeg<file>
    <file>tune.mp3<file>
    <file>image2.jpeg<file>
    </root>@

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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        situ117
        wrote on last edited by
        #3

        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()" }
        

        }@

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

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

          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