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]Turn a ListModel into an xmlModel in toys\corkboards example

[solved]Turn a ListModel into an xmlModel in toys\corkboards example

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

    Hi,

    For practicing, I've tried to write an xmlModel for the toys\corkboards example but a block on the array of notes

    @ListElement {
    name: "Thursday"
    notes: [
    ListElement { noteText: "Meeting\n5.30pm" },
    ListElement { noteText: "Weed garden" }
    ]
    }@

    I think of an xml description like that
    @<day name="Thursday">
    <note>Meeting\n5.30pm</note>
    <note>Weed garden</note>
    </day>@

    I know how to write an xmlModel for the node day but how can I acces the subnode note

    Thanks

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Merinas
      wrote on last edited by
      #2

      I've simplified the application. And I've got a listview of listview of rectangle.
      Here an example of a xml data

      @<data>
      <row>
      <rect size="50"/>
      <rect size="30"/>
      </row>
      <row>
      <rect size="50"/>
      <rect size="30"/>
      <rect size="40"/>
      <rect size="30"/>
      <rect size="40"/>
      </row>
      <row>
      <rect size="50"/>
      <rect size="30"/>
      <rect size="40"/>
      </row>
      </data>@

      And here my qml code

      @import QtQuick 1.0

      Rectangle {
      id: root
      width: 300
      height: 200

      XmlListModel {
      id: xmlFirstModel
      source: "data.xml"
      query: "/data/row"
      }

      Component {
      id:ligne_delegate

      ListView {
      id: listview1
      width: parent.width
      height: 20
      model:XmlListModel {
      source: "data.xml"
      query: "/data/row["+(index+1)+"]/rect"
      XmlRole { name: "rect_width"; query: "{at}size/number()" }
      }
      delegate:Rectangle {
      height:parent.height
      width:rect_width
      color:"red"
      border.color:"black"
      }
      orientation: "Horizontal"
      }
      }

      ListView {
      anchors.fill: parent
      model: xmlFirstModel
      delegate: ligne_delegate
      }
      }@

      There should be more detail about Xpath possibilities in the XmlListModel description, because most of the people who read it, may don't know Xpath. Like me for instance.

      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