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]Nested List Model Dynamic Data Population
QtWS25 Last Chance

[Solved]Nested List Model Dynamic Data Population

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

    Basically what I want to implement is populate list model

    @ListModel {
    id: nestedModel
    }@

    to some thing like,

    @nestedModel.append({
    locationName: qsTr("Location5"),
    collapsed: true,
    folders: [{
    folderName: qsTr("Cam11")
    }, {
    folderName: qsTr("Cam22")
    }, {
    folderName: qsTr("Cam33")
    }, {
    folderName: qsTr("Cam44")
    }]
    })

            nestedModel.append({
                locationName: qsTr("Location1"),
                collapsed: true,
                folders: [{
                     folderName: qsTr("Cam11")
                     }, {
                     folderName: qsTr("Cam22")
                     }, {
                      folderName: qsTr("Cam33")
                     }, {
                     folderName: qsTr("Cam44")
                      }]
              })@
    

    and which works fine.

    But I have to do both parent and child list separately. Here parent is "locationName" and child is "folders"

    I can success fully update "locationName" using

    @for(var i=0;i<locations.length;i++){
    nestedModel.append({
    locationName: locations[i],
    collapsed: true
    })
    }@

    But how can I update "folders" in separate loop as I get the folders list after locations list.

    I already tried like

    @ListModel {
    id:diractories
    }

    diractories.clear();
     for(var j=0;j<dirs.length;j++){
       diractories.append({ folderName: dirs[j] })
       console.log(diractories.get(j).folderName)
    }
    

    nestedModel.set(list_view.currentIndex, {folders: diractories})@
    Where I have added an extra item "folders" at the first time, like

    @nestedModel.append({
    locationName: locations[i],
    collapsed: true
    folders:diractories
    })@

    But all my "folders" list looks same for every "locationName".

    So my question is how can add data for "folders" dynamically?

    Thanks
    Haris

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dasRicardo
      wrote on last edited by
      #2

      Sorry but i don't understand what you want. What is the problem, filling the model, or updating/repainting of the list element? Maybe post you source.

      **Sorry for my english :)

      PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT&#x27;S SOLVED.**

      1 Reply Last reply
      0
      • H Offline
        H Offline
        haris123
        wrote on last edited by
        #3

        hi, thanks for reply..

        Actually I am stuck with filling the model, I can successfully fill the parent, but about child list I am confuced..

        1 Reply Last reply
        0
        • H Offline
          H Offline
          haris123
          wrote on last edited by
          #4

          Finally I found the answer "here":http://www.codeproject.com/Articles/632795/QML-TreeModel-and-TreeView
          I just used below code to append new data to child list,

          @nestedModel.get(index).folders.append({"folderName": "Cam55})
          nestedModel.get(index).folders.append({"folderName": "Cam66})@
          
          1 Reply Last reply
          0
          • D Offline
            D Offline
            dasRicardo
            wrote on last edited by
            #5

            Please add [SOLVED] to your thread title if it's solved.

            **Sorry for my english :)

            PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT&#x27;S SOLVED.**

            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