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
Forum Updated to NodeBB v4.3 + New Features

Copy ListModel or complete ListView Component

Scheduled Pinned Locked Moved QML and Qt Quick
listviewlistmodelcopy
5 Posts 2 Posters 4.0k Views 2 Watching
  • 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 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.

    p3c0P 1 Reply Last reply
    0
    • S sk2212

      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.

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on 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 last edited by
        #3

        Aye.......

        p3c0P 1 Reply Last reply
        0
        • S sk2212

          Aye.......

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on 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 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

            • Login

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