calling model's data() method on demand
-
@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?
-
@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?
@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.
-
@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. -
How much data do you want to display that you need a delayed load? And how do you handle such data?
-
How much data do you want to display that you need a delayed load? And how do you handle such data?
@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). -
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.
-
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.
@Christian-Ehrlicher
yes, i doSELECT COUNT(*) FROM TABLEbefore 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. -
Did you check for which role? I doubt it's the DisplayRole ...
-
Did you check for which role? I doubt it's the DisplayRole ...
@Christian-Ehrlicher
yes it's display role -
The DisplayRole is normaly only requested when the cell is visible - please provide a small example so we can reproduce your issue.