[Qt-interest] QSql(Query|Table)Model without caching possible?
Andre Somers
andre at familiesomers.nl
Thu Feb 25 11:50:48 CET 2010
Davor J. wrote:
> Take this simple example:
> -----------------------------------------------------------
> QSqlTableModel m(0 /*, dbConnction*/);
> m.setTable("test01");
> QTableView v;
> v.setModel(&m);
> m.select();
> v.show();
> -----------------------------------------------------------
>
> Problem here is that the model always caches the whole table. So, if you
> have for example 100k rows, and a slow connection, you might wait a few
> seconds, or a minute. To me, this seems to impede the model/view feature
> which is the speed of visualization of the data. (i.e. the "view" only asks
> the data that it needs, the model is the interface to it.)
>
> My question is, is it possible to bypass the QSqlTableModel's (or
> QSqlQueryModel's) cache? Currently I am thinking about playing with
> fetchMore() and cursors, but if Qt already supports something similar, then
> I don't have to. Btw, my db (Postgres) supports the QSqlDriver::QuerySize
> feature which is mentioned on numerous occasions throughout the
> documentation, and which also seems to be the prerequisite of "non-cached"
> sql-models (...if I understand correctly.)
>
>
I'm not sure if your analysis that it is the cache that is hitting you
is correct. My first guess is, is that the view is actually requesting
data on all items in the model, because you did not tell the view that
all items have the same size. That makes it impossible for the view to
do calculations on how big the view needs to be, and what position of
the scrollbar needs to correspond with what item in the list without
querying all items to get their size.
So, for starters, call QModelView::setUniformItemSizes(true);
André
More information about the Qt-interest-old
mailing list