Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QAbstractTableModel run data() several times even if there are no modifications
Qt 6.12 LTS is out! See what's new in the release blog

QAbstractTableModel run data() several times even if there are no modifications

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 4 Posters 7.2k 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.
  • JonBJ JonB

    @JonexElectronic
    What would you like me to say about this? It is up to you to see what route of code it follows. However, all these calls together take a total of 1/10th of a second, so...? Unless you really are finding that too much, I wonder whether whatever "slow" you are talking about is somewhere else?

    J Offline
    J Offline
    JonexElectronic
    wrote on last edited by JonexElectronic
    #10

    @JonB I'm sure that is the several times that data() is called, because It never stop of being called. And if I hide the QTableView everything works fine.

    JonBJ 1 Reply Last reply
    0
    • jsulmJ jsulm

      @JonexElectronic There are profilers to analyze performance issues. See https://hackingcpp.com/cpp/tools/profilers.html

      J Offline
      J Offline
      JonexElectronic
      wrote on last edited by
      #11

      @jsulm thanks, I will show how to use it

      1 Reply Last reply
      0
      • J JonexElectronic

        @JonB I'm sure that is the several times that data() is called, because It never stop of being called. And if I hide the QTableView everything works fine.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #12

        @JonexElectronic said in QAbstractTableModel run data() several times even if there are no modifications:

        @JonB I'm sure that is the several times that data() is called, because It never stop of being called. And if I hide the QTableView everything works fine.

        Don't know what you mean. I never said data() was not called, I said it is called as you show, and seemingly takes 0.1 seconds.

        I do not believe "it never stop being called". Once the table has been drawn if you do not move the mouse or otherwise interact it should not be being called. Else you have something wrong in your code. Note that if you use the debugger and place breakpoints it may get called, because debugging causes the application to repeatedly gain & lose focus.

        J 1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #13

          data() will be called anytime it needs to repaint (so passing the mouse over it probably triggers it). What you could do is use a QCache<quint64,QVariant> to store previous result and return them without fetching them again (the key would be something like: (static_cast<quint64>(index.column()) << 32) | static_cast<quint64>(index.row()))

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          J 1 Reply Last reply
          3
          • JonBJ JonB

            @JonexElectronic said in QAbstractTableModel run data() several times even if there are no modifications:

            @JonB I'm sure that is the several times that data() is called, because It never stop of being called. And if I hide the QTableView everything works fine.

            Don't know what you mean. I never said data() was not called, I said it is called as you show, and seemingly takes 0.1 seconds.

            I do not believe "it never stop being called". Once the table has been drawn if you do not move the mouse or otherwise interact it should not be being called. Else you have something wrong in your code. Note that if you use the debugger and place breakpoints it may get called, because debugging causes the application to repeatedly gain & lose focus.

            J Offline
            J Offline
            JonexElectronic
            wrote on last edited by JonexElectronic
            #14

            @JonB No, it is done 10 times every 0.001 sec.
            QTime("10:31:01.419")
            QTime("hh:mm:sec.ms")
            Probably I have something wrong. Believe me, it is always being called .

            JonBJ 1 Reply Last reply
            0
            • VRoninV VRonin

              data() will be called anytime it needs to repaint (so passing the mouse over it probably triggers it). What you could do is use a QCache<quint64,QVariant> to store previous result and return them without fetching them again (the key would be something like: (static_cast<quint64>(index.column()) << 32) | static_cast<quint64>(index.row()))

              J Offline
              J Offline
              JonexElectronic
              wrote on last edited by
              #15

              @VRonin I'm not sure how to do that. Could you give me an example?

              1 Reply Last reply
              0
              • J JonexElectronic

                @JonB No, it is done 10 times every 0.001 sec.
                QTime("10:31:01.419")
                QTime("hh:mm:sec.ms")
                Probably I have something wrong. Believe me, it is always being called .

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #16

                @JonexElectronic said in QAbstractTableModel run data() several times even if there are no modifications:

                @JonB No, it is done 10 times every 0.001 sec

                I don't know what you mean. You chose to show some QTime outputs, and they range from QTime("10:31:01.419") to QTime("10:31:01.510"), which is 0.1 seconds. If you meant anything other than that it is not shown. That's all I can say, and never mind.

                Probably I have something wrong. Believe me, it is always being called .

                I asked you to

                Once the table has been drawn if you do not move the mouse or otherwise interact it should not be being called.

                So let it draw. Take your hands of the keyboard and the mouse. Sit there and do nothing. Is data() still being called regularly, yes or no?

                J 1 Reply Last reply
                0
                • JonBJ JonB

                  @JonexElectronic said in QAbstractTableModel run data() several times even if there are no modifications:

                  @JonB No, it is done 10 times every 0.001 sec

                  I don't know what you mean. You chose to show some QTime outputs, and they range from QTime("10:31:01.419") to QTime("10:31:01.510"), which is 0.1 seconds. If you meant anything other than that it is not shown. That's all I can say, and never mind.

                  Probably I have something wrong. Believe me, it is always being called .

                  I asked you to

                  Once the table has been drawn if you do not move the mouse or otherwise interact it should not be being called.

                  So let it draw. Take your hands of the keyboard and the mouse. Sit there and do nothing. Is data() still being called regularly, yes or no?

                  J Offline
                  J Offline
                  JonexElectronic
                  wrote on last edited by
                  #17

                  I took my hands off and It happend. Still being called.

                  JonBJ 1 Reply Last reply
                  0
                  • J JonexElectronic

                    I took my hands off and It happend. Still being called.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #18

                    @JonexElectronic
                    Then it sounds like something else is going on, and you need to discover what.

                    Why don't you start by commenting everything out in your data() and replacing it by, say:

                    QVariant XfTableModelQlist::data(const QModelIndex &index, int role) const
                    {
                        qDebug()<<" IndexColum = "<< index.column() << " IndexRow = " << index.row() << " IndexRole = " << role;
                        if (role==Qt::DisplayRole)
                            return "Hello"
                        return QVariant();
                    }
                    

                    Does it still get called repeatedly now?

                    J 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @JonexElectronic
                      Then it sounds like something else is going on, and you need to discover what.

                      Why don't you start by commenting everything out in your data() and replacing it by, say:

                      QVariant XfTableModelQlist::data(const QModelIndex &index, int role) const
                      {
                          qDebug()<<" IndexColum = "<< index.column() << " IndexRow = " << index.row() << " IndexRole = " << role;
                          if (role==Qt::DisplayRole)
                              return "Hello"
                          return QVariant();
                      }
                      

                      Does it still get called repeatedly now?

                      J Offline
                      J Offline
                      JonexElectronic
                      wrote on last edited by
                      #19

                      @JonB said in QAbstractTableModel run data() several times even if there are no modifications:

                      QVariant XfTableModelQlist::data(const QModelIndex &index, int role) const
                      {
                      qDebug()<<" IndexColum = "<< index.column() << " IndexRow = " << index.row() << " IndexRole = " << role;
                      if (role==Qt::DisplayRole)
                      return "Hello"
                      return QVariant();
                      }

                      Yes it is... My tableView is in a QDockWidget and share the windows with others QDockWidget in the same QMainWindow. It could be the problem?

                      JonBJ 1 Reply Last reply
                      0
                      • J JonexElectronic

                        @JonB said in QAbstractTableModel run data() several times even if there are no modifications:

                        QVariant XfTableModelQlist::data(const QModelIndex &index, int role) const
                        {
                        qDebug()<<" IndexColum = "<< index.column() << " IndexRow = " << index.row() << " IndexRole = " << role;
                        if (role==Qt::DisplayRole)
                        return "Hello"
                        return QVariant();
                        }

                        Yes it is... My tableView is in a QDockWidget and share the windows with others QDockWidget in the same QMainWindow. It could be the problem?

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by
                        #20

                        @JonexElectronic
                        That I would not know. Are you able perhaps to test it outside of a dock widget? But if something is constantly calling your data() method when you are not doing anything at all that is clearly a problem.

                        J 1 Reply Last reply
                        1
                        • JonBJ JonB

                          @JonexElectronic
                          That I would not know. Are you able perhaps to test it outside of a dock widget? But if something is constantly calling your data() method when you are not doing anything at all that is clearly a problem.

                          J Offline
                          J Offline
                          JonexElectronic
                          wrote on last edited by
                          #21

                          @JonB Yes, I have tried it and it does not happen again. Thanks, probably is something that emit a signal to repaint all de Dock? Is it
                          posible??

                          JonBJ 1 Reply Last reply
                          0
                          • J JonexElectronic

                            @JonB Yes, I have tried it and it does not happen again. Thanks, probably is something that emit a signal to repaint all de Dock? Is it
                            posible??

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by
                            #22

                            @JonexElectronic said in QAbstractTableModel run data() several times even if there are no modifications:

                            Thanks, probably is something that emit a signal to repaint all de Dock? Is it
                            posible??

                            Again, sorry, not my area. But if something calls for a repaint/update of a view onto your model you would indeed see the model's data() method being called many times.

                            You need someone else to comment on your currently reported situation with data() being called repeatedly on your dock widget, as this needs not to be happening.

                            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
                            • Unsolved