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



  • 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



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


Log in to reply
 

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