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. How to achieve high performance asynchronous table model update?

How to achieve high performance asynchronous table model update?

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 3.2k Views 3 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.
  • dheerendraD Offline
    dheerendraD Offline
    dheerendra
    Qt Champions 2022
    wrote on last edited by
    #2

    Keep the model & view in a same thread & update the model here. Pull the data in worker thread. Use signals & slots between threads(worker -> UI ) to update the model. Avoid directly accessing the model directly from Worker thread.

    Dheerendra
    @Community Service
    Certified Qt Specialist
    http://www.pthinks.com

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

      Hi,

      To add to @dheerendra, you can also do batch updates rather than updating each and every cell every time you have a change.

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

      J 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        To add to @dheerendra, you can also do batch updates rather than updating each and every cell every time you have a change.

        J Offline
        J Offline
        JohnGa
        wrote on last edited by
        #4

        @SGaist Can you please elaborate a little bit on how to do batched updates?

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

          If you have a high level of updates, only do emit dataChanged for e.g. 500 samples changed.

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

          J 1 Reply Last reply
          1
          • SGaistS SGaist

            If you have a high level of updates, only do emit dataChanged for e.g. 500 samples changed.

            J Offline
            J Offline
            JohnGa
            wrote on last edited by
            #6

            @SGaist @dheerendra Thanks to both of you for the tips.

            1 Reply Last reply
            0
            • dheerendraD dheerendra

              Keep the model & view in a same thread & update the model here. Pull the data in worker thread. Use signals & slots between threads(worker -> UI ) to update the model. Avoid directly accessing the model directly from Worker thread.

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #7

              @dheerendra said in How to achieve high performance asynchronous table model update?:

              Use signals & slots between threads(worker -> UI ) to update the model. Avoid directly accessing the model directly from Worker thread.

              I beg to differ. The worker should update the data interface, which is the model, not the view. The view shouldn't be known to the worker at all.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              0
              • J Offline
                J Offline
                JohnGa
                wrote on last edited by
                #8

                Another question: In a QTableView using a custom model subclassed off of QAbstractTableModel, how can one set the color of a cell based on comparing new and previous value of the cell? for example, if new value is higher than old set the cell background to green.

                kshegunovK 1 Reply Last reply
                0
                • J JohnGa

                  Another question: In a QTableView using a custom model subclassed off of QAbstractTableModel, how can one set the color of a cell based on comparing new and previous value of the cell? for example, if new value is higher than old set the cell background to green.

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #9

                  @JohnGa said in How to achieve high performance asynchronous table model update?:

                  Another question: In a QTableView using a custom model subclassed off of QAbstractTableModel, how can one set the color of a cell based on comparing new and previous value of the cell? for example, if new value is higher than old set the cell background to green.

                  You can do that in the QAbstractItemModel::setData override. When you find that you have different data, you can setData for the same cell (model index) but with Qt::BackgroundRole and provide a different color.

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  0
                  • dheerendraD Offline
                    dheerendraD Offline
                    dheerendra
                    Qt Champions 2022
                    wrote on last edited by
                    #10

                    @kshegunov wonder where I told to update the view from worker ?

                    Dheerendra
                    @Community Service
                    Certified Qt Specialist
                    http://www.pthinks.com

                    kshegunovK 1 Reply Last reply
                    0
                    • dheerendraD dheerendra

                      @kshegunov wonder where I told to update the view from worker ?

                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on last edited by kshegunov
                      #11

                      @dheerendra said in How to achieve high performance asynchronous table model update?:

                      @kshegunov wonder where I told to update the view from worker ?

                      This is how I interpret the following (which I quoted already):

                      Use signals & slots between threads(worker -> UI ) to update the model.

                      The model is not UI, and you can update the model through the view, so I imagined this is what you meant.

                      Read and abide by the Qt Code of Conduct

                      1 Reply Last reply
                      0
                      • dheerendraD Offline
                        dheerendraD Offline
                        dheerendra
                        Qt Champions 2022
                        wrote on last edited by
                        #12

                        @kshegunov Thanks for clarifications. Looks like my answer is misinterpreted.
                        Model is not UI & I did not say this also. Model can be updated from View & this is not in the context of his question.

                        Now, worker Thread is pulling the data. Since model is in another thread use signals & slots to update the model which is in another thread. This is the only thing I said in my answer.

                        Dheerendra
                        @Community Service
                        Certified Qt Specialist
                        http://www.pthinks.com

                        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