[Qt-interest] QSql(Query|Table)Model without caching possible?

Davor J. DavorJ at live.com
Thu Feb 25 12:19:40 CET 2010


Thanks Andre. It's an interesting suggestions which I have overlooked. But 
it's not the case.

Even if I set up the model without the view:
-----------------------------------------------------------
    QSqlTableModel m(0 /*, dbConnction*/);
    m.setTable("test01");
    m.select();
-----------------------------------------------------------
... the application freezes and the network connection peaks for some 10 
seconds. So there is no difference whether there is a view or not.

(I know... this could be solved with threading or allowing the app events to 
pass, but then it also goes beyond my initial question. I don not need to 
cache all the data if I only need a few.)

Regards,
Davor


"Andre Somers" <andre at familiesomers.nl> wrote in message 
news:4B865608.2000906 at familiesomers.nl...
> 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