Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] QStandardItemModel deep copy
QtWS25 Last Chance

[solved] QStandardItemModel deep copy

Scheduled Pinned Locked Moved General and Desktop
deep copyqstandarditemmo
8 Posts 2 Posters 3.5k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on 6 May 2015, 11:44 last edited by A Former User 5 Nov 2015, 08:04
    #1

    Hi there!
    I'm writing a function that updates the contents of a QStandardItemModel that has a more complex structure than just tree or table shape (it's actually a combination of both, having tables as children). For security, instead of immediately altering the actual model, my function builds up a temporary model and, if successful, replaces the actual model by the temporary one.
    Of course, I can't just set the model pointer to the temporary model, as there are widgets pointing to the old model (which would then be destroyed). Therefore I decided to keep the old model and first clear it, then copy the contents of the temporary model in to the actual model.
    Unfortunately, I don't know how to get a deep copy of the temporary model. Does anyone have any ideas for deep copy, or even an alternative approach to solve my problem?
    Thx in advance!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 6 May 2015, 22:08 last edited by
      #2

      Hi,

      If I understand you correctly, you have a custom structure/class that handles your data, right ? If so, what about just changing that structure with the new one ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on 8 May 2015, 08:09 last edited by
        #3

        Hi Samuel,
        that's exactly what I would like to do. However, I can't figure out how to do that without calling setModel() again for all widgets that point to the model.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 8 May 2015, 22:26 last edited by
          #4

          Add your own API to exchange/update/replace your data structure. Doing so, it becomes your model's role to propagate the fact that there are new data arriving (which he already does). No need to replace any model

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          ? 1 Reply Last reply 9 May 2015, 07:08
          0
          • S SGaist
            8 May 2015, 22:26

            Add your own API to exchange/update/replace your data structure. Doing so, it becomes your model's role to propagate the fact that there are new data arriving (which he already does). No need to replace any model

            ? Offline
            ? Offline
            A Former User
            wrote on 9 May 2015, 07:08 last edited by
            #5

            Sorry if this question is somewhat ridiculous, but I don't see how I could backup the old model with such an implementation. My goal is to update the model and revert those changes in case of failure.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 9 May 2015, 22:53 last edited by
              #6

              What changes between the new and old is that the new model internal data structure changes so if you have your own model, you can share the new model internal data with the soon to be replaced one.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on 10 May 2015, 08:00 last edited by
                #7

                Thank you Samuel!

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 10 May 2015, 21:16 last edited by
                  #8

                  You're welcome !

                  If you have everything running now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  6/8

                  9 May 2015, 22:53

                  • Login

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