PDA

View Full Version : Is it useful to implement fetchMore() in this context?



tuli
18th May 2018, 10:18
Hi,

I have a simple data model that basically encapsulates a std::vector with data. Data only exists in this vector, and the vector can potentially grow very large.

Now I have implemented canFetchMore() and fetchMore() in so far, that I just keep an integer with the current size, and override the two fetch methods basically like so



canFetchmore() { return current_size < rowCount(); }
fetchMore() { current_size = std::min(current_size + 1000, rowCount()); }


I thought this might take some pressure of the GUI.


But now that I think about it some more, Qt is probably smart enough to do something like this on its own. I am thinking now the fetch-more stuff only applies when I am fetching data in a very costly manner, say from SQL DB, not when I have it all here in a std::vector.


Is this thinking right, or does it make sense to override the fetch methods like I did?

d_stranz
18th May 2018, 20:38
Is this thinking right, or does it make sense to override the fetch methods like I did?

Yes, and no. You already have the data in memory, so there's really nothing to fetch. The fetchMore() and canFetchMore() are intended for the expensive operations where data isn't held directly in memory until needed. If you were storing your data in a cache that can hold only part of it, then you would need to implement these methods.

And yes, the model-view GUI is smart enough to do this on its own - QTableView, for example, will only ask for what is actually able to be visible on screen.

I do not know about the interaction between rowCount(), canFetchMore(), and fetchMore() though. I suppose that if rowCount() returns a number smaller than the number of rows that could be displayed, the view calls canFetchMore() to determine if there is more data available, and then fetchMore() if it is.

tuli
25th May 2018, 16:44
Thanks, it indeed seems I do not need fetch-related stuff.