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. QAbstractItemModel & QThread [Solved]
Forum Updated to NodeBB v4.3 + New Features

QAbstractItemModel & QThread [Solved]

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.4k Views 1 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.
  • G Offline
    G Offline
    gaijinpunch
    wrote on last edited by
    #1

    Hi

    I've made a handful of read-only classes that inherit QAbstractTableModel. I'm about to do my first editable one. There's a good chance that multiple views will be in their own QThreads... and that a separate thread (3rd party library) might actually update the model as well.

    I'm curious about a few things. For starters, there are 4 member functions of QStyledItemDelegate which need to be reimplemented to allow the model to be updated graphically. I'm using the argument (const QModelIndex&) in each of these to determine what type of widget to to create ,and also where to put the data. If the model changes between these calls, is the index still pointing to the one that needs to be chagned? I would think not. Do I need to to come up w/ my own fancy way of keeping track of which index to update? Do I need to deal w/ a mutex locker when calling setModelData()?

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

      Hi,

      Multiple view in their own thrown thread ? Are you thinking of using widget in secondary threads ?

      As for you secondary question, the index validity will depend on how the model is changed. But anyway, like always when thread are in the game, you have to protect the access to the data that you are accessing. Mutex or read/write lock it's up to you to decide what suits the best.

      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
      • G Offline
        G Offline
        gaijinpunch
        wrote on last edited by
        #3

        I was imagining a design in which multiple QDialog's were spawned off of a central one in the GUI loop. So that's not going to happen, no? I suppose if I'm inheriting a 3rd party class which does some magic under the sheets, I inheriting that in some type of QObject (not QWidget) and then putting that in it's own QThread is a better design?

        EDIT: Do I even need to do that? If I have a QObject like a subclassed QAbstractTableModel which is also inheriting something like MyColleaguesLibrary which runs multiple pthreads and calls a callback every time the data is updated, should I even bother w/ QThread? In this case, the 3rd party library is probably using pthread, but could also be single-threaded I suppose.

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

          No problem spawning QDialogs from another widget, it's spawning QDialog from a secondary thread that's not possible.

          That design decision will depend on how your third party library works and what it does

          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
          • G Offline
            G Offline
            gaijinpunch
            wrote on last edited by
            #5

            Cool -- thanks.

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

              You're welcome !

              If this answers your questions, then 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

              • Login

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