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. XMLListModel inside a repeater (nested models)

XMLListModel inside a repeater (nested models)

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

    Hi,
    I'm trying to generate nested ListViews based on multiple XMLListModel queries (different queries on the same source file).
    I can succesfully create the outer list, using the outerModel "count", but the innerList only displays the first element of the inner model and not all of them (despite the model count being correct)

    What am I doing wrong? May the problem be related to some sort of race condition and/or model loading?

    My minimum test code is below.
    Thank you for your help

    Stef

    main.qml

    import QtQuick 2.15
    import QtQuick.Controls 2.15
    import QtQuick.Window 2.15
    
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
    
        LabBook {
            anchors.fill: parent
        }
    
    }
    

    LabBook.qml

    import QtQuick 2.0
    import QtQuick.Controls 2.0
    import QtQuick.Layouts 1.14
    import QtQuick.XmlListModel 2.0
    
    Item {
    
        XmlListModel {
            id: outerModel
            source: "qrc:/labbook.xml"
            query: "/book/plate"
            XmlRole { name: "id_plate"; query: "@id/number()" }
        }
    
        ColumnLayout {
            anchors.fill: parent
            anchors.margins: 10
    
            // content
            RowLayout {
    
                // plates
                ListView {
                    id: listPlates
                    Layout.preferredWidth: 200
                    Layout.fillHeight: true
                    model: outerModel
                    delegate: Button {
                        text: "Plate " + id_plate
                    }
                }
    
                // notes
                ColumnLayout {
                    Repeater {
                        id: rep
                        model: outerModel.count
                        delegate: Rectangle {
    
                            Layout.preferredHeight: 100
                            Layout.fillWidth: true
                            color: "green"
    
                            XmlListModel {
                                id: innerModel
                                source: outerModel.source
                                query: "/book/plate[" + (modelData+1) + "]/session"
                                XmlRole { name: "day"; query: "@day/string()" }
                            }
    
                            // title
                            Label {
                                id: title
                                text: "Plate " + outerModel.get(modelData).id_plate
                            }
    
                            // list of notes
                            ListView {
                                anchors.top: title.bottom
                                id: listNotes
                                model: innerModel
                                delegate: Text { height: 25; text: day }
                                onCountChanged: console.log("ListView count: ", count)
                            }
                        }
                    }
                }
    
            }
        }
    }
    

    labbook.xml

    <?xml version="1.0" encoding="utf-8"?>
    <book>
       <plate id="123">
          <session day="A1"></session>
            <session day="A2"></session>
            <session day="A3"></session>
       </plate>
        <plate id="456">
          <session day="B1"></session>
          <session day="B2"></session>
       </plate>
       <plate id="789">
          <session day="C1" dd="01" mm="03" yyyy="2021" />
          <session day="C2" dd="01" mm="03" yyyy="2021" />
       </plate>
    </book>
    
    1 Reply Last reply
    0
    • C Offline
      C Offline
      cooked
      wrote on last edited by
      #2

      The problem is solved making the height of the "listNotes" explicit, like

      ListView {
            anchors.top: title.bottom
            id: listNotes
            height: 50
            model: innerModel
            delegate: Text { height: 25; text: day }
            onCountChanged: console.log("ListView count: ", count)
      }
      

      or similarly with anchors.fill, Layout, etc...

      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