PDA

View Full Version : Handling mass data with QTreeView/QTableView



alsuffndruff
2nd October 2006, 00:22
Hallo all,

I am just wondering how to handle big amounts of data with the above mentioned views. I am using Qt 4.1.4. My problem here is:

I have a big amount of data (e.g. 100000 items) stored in an MySQL database that can only be retrieved via a special interface (usage of QtSQL classes therefore not possible here).
Retrieving these items is not very fast and so I thought it would be a good idea to implement a kind of cache that handles 50 items (which is the maximum amount of data that can be shown in the view) and reload other items by the underlying model within the index() method into the cache when the appropriate index is called (e.g if index 51 is called, the first item in my cache is thrown away since it is no more visible in the view and the item 51 is loaded from the database). The models rowCount() method is set to 100000 in this example.

This approach seemed to work so far for a QTableView. My problem now is when I am trying a similar approach with a QTreeView I am running into problems since QTreeView seems to call the models index() method for all items from 0 to rowCount() even if these are not visible.

So I am wondering if my approach is wrong or if there is something I can do to hinder QTreeView from calling index() for all items even if these are not visible.

Thanks for any hint
Greetings
Kai

PS: CUrrently playing with QT4.2 rc1. Seems that the QTableView of this version now behaves as the QTreeView in my above example. My problem now becomes more urgent because it seems that my approach is wrong.

wysota
2nd October 2006, 00:33
It's hard to say. In theory you can limit the rowcount to the real value and use canFetchMore and fetchMore to return additional parts of data, but I'm not sure how it will work in this case.
Some other idea might be to use some other method than index() to trigger the fetch, for example the data() method. But all this is risky, you should think about a better way to fill the full model (for example fetch items for the model in a separate thread).