PDA

View Full Version : Paging a QTableView



Jimmy2775
3rd November 2006, 23:06
The application I'm working on uses a QTableView to display data from the database. The problem that I'm having is that when the application loads, the table calls the data() method for every cell, even cells that aren't visible. Since I'm displaying thousands of rows of data, this causes quite a lag on startup.

To solve this problem I'm considering some way to "page" through the data. By that I mean that I only want to make the data() call to the backend when the row actually becomes visible. My initial idea is to determine the correct row and column counts and then build a table full of empty cells. Somehow I'd like to create an "rowIsVisible" signal that table can emit when new rows become visible and that would trigger the call to the backend. Has anyone tried anything similar to this? Any ideas/thoughts/experiences on the subject are greatly appreciated.

Thanks,

Jimmy

wysota
4th November 2006, 08:03
Do you use QSqlTableModel or its subclass or a custom model? It should work fine for volume of data this big. The problem with what you want to do is that you would probably need to reimplement the view itself as well as the model as only the view knows what data is visible. The situation becomes very complicated if you want to have two views... Maybe it would better to implement some kind of cache for your data?

Jimmy2775
6th November 2006, 17:48
Do you use QSqlTableModel or its subclass or a custom model?
I've subclassed QAbstractTableModel to make calls to a proprietary DB we're using.


The problem with what you want to do is that you would probably need to re-implement the view itself as well as the model as only the view knows what data is visible. The situation becomes very complicated if you want to have two views... Maybe it would better to implement some kind of cache for your data?

Fortunately there is only one view, so that shouldn't be an issue. I have implemented a cache, but the issue is when the application first loads before the cache is populated. The initial call to the DB takes so much time that it makes the app unusable.

Thanks for your ideas wysota.

wysota
6th November 2006, 17:54
Maybe you could write your own database driver (if it conforms to SQL) so that you can use the standard model?

If that's not an option, I suggest you take a look at QSqlQueryModel sources to see how Qt handles remote models without a major speed penalty.