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 ListModel or complete ListView Component
QtWS25 Last Chance

Copy ListModel or complete ListView Component

Scheduled Pinned Locked Moved QML and Qt Quick
listviewlistmodelcopy
5 Posts 2 Posters 4.0k 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.
  • S Offline
    S Offline
    sk2212
    wrote on 21 Jul 2015, 12:25 last edited by
    #1

    I want to "save" a model state within a ListView.

    I fact I have created a navigation tree where you can click on a folder and the content of the listview model will be updated with the content of this folder.

    So, how to backup e.g the parent folder?

    I try to push the list model on a stack with

    stack.push("backup.qml", {listModel: list.model})

    but it seems that it only stores the reference of the model. If the model changes also the "backup" on the stack will change. I need something like a deep copy for qml elements.

    P 1 Reply Last reply 21 Jul 2015, 16:22
    0
    • S sk2212
      21 Jul 2015, 12:25

      I want to "save" a model state within a ListView.

      I fact I have created a navigation tree where you can click on a folder and the content of the listview model will be updated with the content of this folder.

      So, how to backup e.g the parent folder?

      I try to push the list model on a stack with

      stack.push("backup.qml", {listModel: list.model})

      but it seems that it only stores the reference of the model. If the model changes also the "backup" on the stack will change. I need something like a deep copy for qml elements.

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 21 Jul 2015, 16:22 last edited by
      #2

      Hi @sk2212,
      Do you mean you want to copy the contents of a ListModel ?

      157

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sk2212
        wrote on 22 Jul 2015, 06:22 last edited by
        #3

        Aye.......

        P 1 Reply Last reply 22 Jul 2015, 07:48
        0
        • S sk2212
          22 Jul 2015, 06:22

          Aye.......

          P Offline
          P Offline
          p3c0
          Moderators
          wrote on 22 Jul 2015, 07:48 last edited by
          #4

          @sk2212 Wouldn't iterate and access elements work in your case ? ListModel has methods that can be useful.

          157

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sk2212
            wrote on 22 Jul 2015, 12:28 last edited by
            #5

            Hmmm...okay, I think it works now.

            I will create "backup.qml" dynamically with Qt.createComponent() and createObject(root, {listModel: ListModel}).

            After that I access the property listModel in the created component, iterate over the current listModel which should be backuped and append that items in the listModel of the new-created component.

            At the end I push the new-created component on stack to be able to backup more than one "state" of the model.

            1 Reply Last reply
            0

            1/5

            21 Jul 2015, 12:25

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved