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. calling model's data() method on demand
Forum Updated to NodeBB v4.3 + New Features

calling model's data() method on demand

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 4 Posters 1.1k 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.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by
    #1

    i have a table view which should be able to display millions of rows. to make this efficient, i have decided not to populate the table view at once. i want to populate only the visible area of the table plus say 100 rows. then when the user scrolls down, populate that part of the table.

    currently when i tell the model it has say 10000 rows, data() is called 10000 times and the table is fully filled.

    how can i make an on-demand call to data()?

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

      Hi,

      What kind of on demand do you have in mind ?

      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
      1
      • U Offline
        U Offline
        user4592357
        wrote on last edited by
        #3

        i want data () to be called when the table cell becomes visible.
        in other words, there's no sense to fill the whole table if only day 20 rows of it are visible.

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @user4592357 said in calling model's data() method on demand:

          in other words, there's no sense to fill the whole table if only day 20 rows of it are visible.

          Where do you get the data from? Did you take a look at QAbstractItemModel::canFetchMore?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          VRoninV 1 Reply Last reply
          2
          • Christian EhrlicherC Christian Ehrlicher

            @user4592357 said in calling model's data() method on demand:

            in other words, there's no sense to fill the whole table if only day 20 rows of it are visible.

            Where do you get the data from? Did you take a look at QAbstractItemModel::canFetchMore?

            VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            @Christian-Ehrlicher said in calling model's data() method on demand:

            Did you take a look at QAbstractItemModel::canFetchMore?

            This is the correct solution but a word of warning: that's a one-time-only thing though. once the user scrolled to the bottom you have all the data loaded in memory and you go back to the starting point.

            "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

            1 Reply Last reply
            0
            • U Offline
              U Offline
              user4592357
              wrote on last edited by
              #6

              @Christian-Ehrlicher
              thanks. i'm looking at Fetch More Example and it seems to be what i need, but...

              @VRonin
              also it has another bad side. say the user scrolls down really fast. in that case i would like to populate only the visible area of the table. whereas this method will populate model up until the current scrollbar position.

              1 Reply Last reply
              0
              • Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                How much data do you want to display that you need a delayed load? And how do you handle such data?

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                U 1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  How much data do you want to display that you need a delayed load? And how do you handle such data?

                  U Offline
                  U Offline
                  user4592357
                  wrote on last edited by
                  #8

                  @Christian-Ehrlicher
                  still not sure. but i want the table to be populated immediately. i'll decide on the number later, maybe 100000?

                  the data is to be taken by executing a sql query.
                  the way i picture it is to execute the query by limiting the number of results (say, LIMIT 100000), and if the current row is greater than what i have currently (i.e. 100000), then i'll query the database again by specifying a limit and offset (LIMIT 100000 OFFSET 100000).

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Online
                    Christian EhrlicherC Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    So you must do a select count(*) before. And in the end you've all data in the model. Nothing retains you from doing a select as soon as data() is called for a specific row so I don't see any problem - yu just have to remember which rows you already fetched.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    U 1 Reply Last reply
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      So you must do a select count(*) before. And in the end you've all data in the model. Nothing retains you from doing a select as soon as data() is called for a specific row so I don't see any problem - yu just have to remember which rows you already fetched.

                      U Offline
                      U Offline
                      user4592357
                      wrote on last edited by
                      #10

                      @Christian-Ehrlicher
                      yes, i do SELECT COUNT(*) FROM TABLE before anything else. that's the problem. when i set the row count to that number, data() is called for all the rows, and i don't know how to "stop" it.

                      1 Reply Last reply
                      0
                      • Christian EhrlicherC Online
                        Christian EhrlicherC Online
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        Did you check for which role? I doubt it's the DisplayRole ...

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        U 1 Reply Last reply
                        0
                        • Christian EhrlicherC Christian Ehrlicher

                          Did you check for which role? I doubt it's the DisplayRole ...

                          U Offline
                          U Offline
                          user4592357
                          wrote on last edited by
                          #12

                          @Christian-Ehrlicher
                          yes it's display role

                          1 Reply Last reply
                          0
                          • Christian EhrlicherC Online
                            Christian EhrlicherC Online
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            The DisplayRole is normaly only requested when the cell is visible - please provide a small example so we can reproduce your issue.

                            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                            Visit the Qt Academy at https://academy.qt.io/catalog

                            1 Reply Last reply
                            1

                            • Login

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