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. Browsing through nested items in XmlListModel: XPath Query question
Forum Update on Monday, May 27th 2025

Browsing through nested items in XmlListModel: XPath Query question

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 3.3k 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.
  • M Offline
    M Offline
    mpvader2
    wrote on 1 Apr 2011, 15:57 last edited by
    #1

    Hi All,

    I am trying to make a little program that iterates through an xmlfile with childs that are actually submenus. I am almost there, the last thing missing is a way to tell the ListView delegate what query it should pass back to the XmlListModel when the item is clicked. And also a query to determine if certain children exists. I find it a bit hard to explain, please have a look at below example. What I really want is to get rid of the 'subMenuQuery' element in the xml file. Can that be done?

    So line 14 in the qml file needs to be some more elaborate XPath query. Or perhaps in line 24 I can find out which index this listviewitem has, so I can use it to create a string containing the new query for the XmlListModel?

    For your reference, the codes. First the XML File
    @
    <?xml version="1.0" encoding="utf-8"?>
    <items>
    <item>
    <title>Battery voltage</title>
    <value>13.4V</value>
    </item>
    <item>
    <title>Battery current</title>
    <value>+0.3A</value>
    </item>
    <item>
    <title>Submenu</title>
    <value>-90Ah</value>
    <subMenuQuery>/items/item[3]/items/item</subMenuQuery>
    <items>
    <item>
    <title>Submenitem1</title>
    <value>1</value
    </item>
    <item>
    <title>Submenitem2</title>
    <value>2</value
    </item>
    </items>
    </item>
    </items>
    @

    The qml file:
    @
    import QtQuick 1.0

    Rectangle {
    width: 480
    height: 272

    XmlListModel {
        id: xmlModel
        source: "lynxshunt.xml"
        query: "/items/item"
    
        XmlRole { name: "title"; query: "title/string()" }
        XmlRole { name: "value"; query: "value/string()" }
        XmlRole { name: "subMenuQuery"; query: "subMenuQuery/string()" }
    }
    
    ListView {
        id: listView;
        anchors.fill: parent;
        model: xmlModel;
        delegate: MyListItemDelegate {
            deviceName: title
            deviceValue: listView.currentIndex.toString()
            submenuQuery: subMenuQuery
            lv: xmlModel
    
        }
    }
    

    }

    @

    The delegate:
    @
    import QtQuick 1.0

    Rectangle {
    id: rectangle1
    width: 480
    height: 54

    property string deviceName: "";
    property string deviceValue: "";
    property string submenuQuery: "";
    property XmlListModel lv;
    
    MouseArea {
        anchors.fill: parent
        onClicked: {
            if (submenuQuery != "") { lv.query = submenuQuery }
        }
    }
    
    Text {
        id: deviceNameText
        anchors.left:  parent.left; anchors.leftMargin: 20
        anchors.top:  parent.top; anchors.topMargin: 5
        text: rectangle1.deviceName
    }
    
    Text {
        id: deviceSummaryText
        anchors.left:  parent.left; anchors.leftMargin: 20
        anchors.bottom:  parent.bottom; anchors.bottomMargin: 8
        text: rectangle1.deviceValue
    }
    

    }
    @

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Merinas
      wrote on 5 Apr 2011, 09:39 last edited by
      #2

      What I've understood of your problem, is you need a support for nested xml in qml ?
      If that so , there is no support yet but you could follow the "bug report":http://bugreports.qt.nokia.com/browse/QTBUG-13688?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel#issue-tabs .

      1 Reply Last reply
      0

      1/2

      1 Apr 2011, 15:57

      • Login

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