Is QTableView using lazy population?
I have a model which gets its data from a sqlite database with many many entries, here I implemented my custom model, where every QModelIndex creation is associated with a SQL query.
Now my question is:
What happens when I set the my model on a QTableView?
Are all entries (indexes) loaded at once or only the visible entries (rows)? Like on Android with its cursors...
In other words:
Does each item delegate load the respective index only if currently visible (lazy loading)?
Just found this discussion on the mailing list: http://lists.trolltech.com/qt-interest/2007-05/thread01132-0.html
seems to confirm that a QTableView queries only the indexes that are actually visible on the viewport area.
Is that right?
Yes, that is correct. The view only queries what it needs to paint.
QSqlTableModel (possibly QSqlQueryModel) also does lazy loading in blocks of 256 (maybe 255) rows. So, if you have many rows you will experience short model-induced delays as you scroll into new territory. If normal use dictates, and memory permits, you can force it to load using QAbstractItemModel::canFetchMore() and QAbstractItemModel::fetchMore() and after that scroll is much less interrupted.
I'm not using the QSqlTableModel or any other existing SQL model because my model queries data from SQL table joins and unions, which are not supported by those models (read only).
So i'm going to use a custom model which uses QSqlQuery as its base or subclass QSqlQueryModel to add write methods...