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. Copy qml list elements from one model to another
Qt 6.11 is out! See what's new in the release blog

Copy qml list elements from one model to another

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 3 Posters 5.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.
  • V Offline
    V Offline
    Valerian
    wrote on last edited by
    #1

    Hi All,

    I have two list models

    ListModel{id: nameModel}
    ListModel{id: selectedNameModel}
    

    The name model is filled from the backend using the

    nameModel.append({'name':'Sam','age':23})
    nameModel.append({'name':'Tom','age':25})
    

    On a click operation on the listview containing the nameModel, I want to populate the selectedNameModel.

    Could you suggest the most efficient way to do so?

    M 1 Reply Last reply
    0
    • V Valerian

      Hi All,

      I have two list models

      ListModel{id: nameModel}
      ListModel{id: selectedNameModel}
      

      The name model is filled from the backend using the

      nameModel.append({'name':'Sam','age':23})
      nameModel.append({'name':'Tom','age':25})
      

      On a click operation on the listview containing the nameModel, I want to populate the selectedNameModel.

      Could you suggest the most efficient way to do so?

      M Offline
      M Offline
      medyakovvit
      wrote on last edited by
      #2

      @Valerian, what you think about this:

      ListModel{id: nameModel}
      ListModel{id: selectedNameModel}
      
      Listview{
          // ...
          model: nameModel
          delegate: Component{
              // for example
              Rectangle{
                  // ...
                  MouseArea{
                      anchors.fill: parent
                      onClicked: selectedNameModel.append(nameModel.get(index))
                  }
              }
          }
      }
      
      V 1 Reply Last reply
      2
      • M medyakovvit

        @Valerian, what you think about this:

        ListModel{id: nameModel}
        ListModel{id: selectedNameModel}
        
        Listview{
            // ...
            model: nameModel
            delegate: Component{
                // for example
                Rectangle{
                    // ...
                    MouseArea{
                        anchors.fill: parent
                        onClicked: selectedNameModel.append(nameModel.get(index))
                    }
                }
            }
        }
        
        V Offline
        V Offline
        Valerian
        wrote on last edited by
        #3

        @medyakovvit Thanks.. It worked..

        M 1 Reply Last reply
        0
        • V Valerian

          @medyakovvit Thanks.. It worked..

          M Offline
          M Offline
          medyakovvit
          wrote on last edited by
          #4

          @Valerian could you check what will happen when you delete some item from nameModel previously added to selectedNameModel?

          V M 2 Replies Last reply
          0
          • M medyakovvit

            @Valerian could you check what will happen when you delete some item from nameModel previously added to selectedNameModel?

            V Offline
            V Offline
            Valerian
            wrote on last edited by Valerian
            #5

            @medyakovvit It works fine..

            1 Reply Last reply
            1
            • M medyakovvit

              @Valerian could you check what will happen when you delete some item from nameModel previously added to selectedNameModel?

              M Offline
              M Offline
              Mohammad Kanan
              wrote on last edited by
              #6

              @medyakovvit said in Copy qml list elements from one model to another:

              @Valerian could you check what will happen when you delete some item from nameModel previously added to selectedNameModel?

              Seems no deep copy! .. appended items will be lost .. !

              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