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. Moving QAbstractItemModel Subclass Instance from Main GUI Thread to Worker Thread When Used in a QTreeView
Forum Updated to NodeBB v4.3 + New Features

Moving QAbstractItemModel Subclass Instance from Main GUI Thread to Worker Thread When Used in a QTreeView

Scheduled Pinned Locked Moved Unsolved General and Desktop
39 Posts 3 Posters 4.3k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #30

    That's what makes it "unclean". The worker object should do the heavy processing and then populate the model through signals and slots, not create it.

    Out of curiosity, what kind of heavy lifting must be done ?

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

    C 1 Reply Last reply
    1
    • SGaistS SGaist

      That's what makes it "unclean". The worker object should do the heavy processing and then populate the model through signals and slots, not create it.

      Out of curiosity, what kind of heavy lifting must be done ?

      C Offline
      C Offline
      Crag_Hack
      wrote on last edited by Crag_Hack
      #31

      That's what makes it "unclean". The worker object should do the heavy processing and then populate the model through signals and slots, not create it.

      How does one populate through signals/slots? I am dealing with potentially multiple tens of thousands of items in the trees so it doesn't make sense to signal/slot each item does it?

      Also what's so bad about this approach that makes things 'unclean'. Doesn't it work fine? Are there any critical flaws?

      Out of curiosity, what kind of heavy lifting must be done ?

      This particular tree displays file/directory structures and allows the user to manipulate them.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #32

        You don't have to signal each and every change, that's when you make your code smart and do batch updates for example.

        Also, performance wise, there's the question of the interest of having tens of thousands of items loaded at the same time in memory. Are they worth being all loaded or would a subset make more sense ? For example, would it make sense to load all the files from the root of your disk ? Also, do your users really need to have all the data pre-loaded or would "just in time" details be enough ?

        Then, why is there a need to remove the model from the view when there's an action to be done with its data ? Here is the potential code smell. There should be no need for that in the first place.

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

        C 2 Replies Last reply
        0
        • SGaistS SGaist

          You don't have to signal each and every change, that's when you make your code smart and do batch updates for example.

          Also, performance wise, there's the question of the interest of having tens of thousands of items loaded at the same time in memory. Are they worth being all loaded or would a subset make more sense ? For example, would it make sense to load all the files from the root of your disk ? Also, do your users really need to have all the data pre-loaded or would "just in time" details be enough ?

          Then, why is there a need to remove the model from the view when there's an action to be done with its data ? Here is the potential code smell. There should be no need for that in the first place.

          C Offline
          C Offline
          Crag_Hack
          wrote on last edited by Crag_Hack
          #33

          You don't have to signal each and every change, that's when you make your code smart and do batch updates for example.

          Can you show me some brief code/pseudocode or elaborate? I still don't know how to populate in this regard.

          Also, performance wise, there's the question of the interest of having tens of thousands of items loaded at the same time in memory. Are they worth being all loaded or would a subset make more sense ? For example, would it make sense to load all the files from the root of your disk ? Also, do your users really need to have all the data pre-loaded or would "just in time" details be enough ?

          I just did a benchmark and loading a tree of 50,000 items several levels deep only increased memory consumption from 12 MB to 51 MB. Also the tree loaded in 10 seconds or so. So maybe down the road I can change things but for now I'm just looking forward to completion sooner rather than later.

          Then, why is there a need to remove the model from the view when there's an action to be done with its data ? Here is the potential code smell. There should be no need for that in the first place.

          The items have state in member variables for processing and also once the user has completed interaction with the view the model gets sent to the worker thread for processing. The view is no longer needed at this point; hence my original question about if I need to do anything to the views before I send the model off for processing.

          Here is the potential code smell.

          Is this the 'unclean' part? Is the rest a proper approach? This is the most important question for me for now.

          Also I was hoping this thread would serve for other Googlers out there looking for a quick and easy simple solution to this scenario; this scenario must be pretty common.

          Thanks for your time :)

          1 Reply Last reply
          0
          • SGaistS SGaist

            You don't have to signal each and every change, that's when you make your code smart and do batch updates for example.

            Also, performance wise, there's the question of the interest of having tens of thousands of items loaded at the same time in memory. Are they worth being all loaded or would a subset make more sense ? For example, would it make sense to load all the files from the root of your disk ? Also, do your users really need to have all the data pre-loaded or would "just in time" details be enough ?

            Then, why is there a need to remove the model from the view when there's an action to be done with its data ? Here is the potential code smell. There should be no need for that in the first place.

            C Offline
            C Offline
            Crag_Hack
            wrote on last edited by
            #34

            You don't have to signal each and every change, that's when you make your code smart and do batch updates for example.

            Thought about this a little... do I just create the tree model's items in the worker thread then pass the root model item to the main GUI thread for use in the model?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #35

              Are you creating a custom data structure ?

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

              C 1 Reply Last reply
              0
              • SGaistS SGaist

                Are you creating a custom data structure ?

                C Offline
                C Offline
                Crag_Hack
                wrote on last edited by
                #36

                Yes just a tree item structure guy with the relevant parent and children functions and data relevant to the state of the items.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #37

                  Sounds good.

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

                  C 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Sounds good.

                    C Offline
                    C Offline
                    Crag_Hack
                    wrote on last edited by
                    #38

                    Awesome thanks now I know how to do things... I'm left with one question out of curiosity: what kinda problems can passing the model between threads cause?
                    Thanks for everything

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #39

                      Data access from different threads without proper locking for example. In your case, you are removing and adding the model back to the view but it's not good practice in the sense that there should be no need for that. And as I wrote before, a model can be accessed by multiple views or other objects so you would also have to track these properly.

                      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

                      • Login

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