PDA

View Full Version : QSqlTableModel & treeview



janEUcitzen
14th November 2008, 08:52
Hi

I am relatively new to Qt so let me start by excusing for not knowing the "obvious".

I have a mysql table (actually a complicated view) with 4.000.000 entries or approx. 40Gb worth of data.

I want to make an application where the user can browse through these data, and found QSqlTableModel together with Qtreeview perfect for the job...

however how do I stop QSqltableModel from trying to read all 4.000.000 entries in one chunck ???? (I do not have enough ram on my notebook).

What I actually looked for was a widget/model, with a treeview layout, and with buttons for next chunk, previous chunk....but I have not been able to find any example code ?

Am I on the right track, or do I have to programm everything myself ??

thanks in advance for a reply...

jan

caduel
14th November 2008, 09:47
I thought QSqlTableModel etc read data on demand?
(I.e. when you scroll down, further data is requested...)
Have you checked that all the data is read right at the start?

janEUcitzen
14th November 2008, 10:10
Hi.

that was my understanding too...but after my PC melted down...I ran a mysql trace, to see the statements issued..

and Qt just sent a normal select...... without the "limit" parameter, meaning mysql collects all data at once...and the treeview explodes.

but admitted I have also not found anywhere to define how big chuncks treeview should display...there does not seem to be a setCount(), displayNext(), displayPrevious() methods...

jan

caduel
14th November 2008, 10:37
* check QSqlQueryModel::fetchMore()
* check if your database driver has that feature

janEUcitzen
14th November 2008, 11:24
hi.

I use the standard mysql driver supplied with Qt4.4.1...

If I look at the documentation of fetchMore is says:

Fetches more rows from a database. This only affects databases that don't report back the size of a query (see QSqlDriver::hasFeature()).

and mysql reports the rowcount back...just to be sure I checked in the source of the driver, and it sets the feature..

but do you know if I can force that feature off, with the standard mysql driver ??

jan

janus
14th November 2008, 15:17
Hi,

there is an app at qt-apps.org (http://www.qt-apps.org/content/show.php/Thetyss+Data+Browser?content=76696) that does not use a treeview but seems to deal with a similar problem (huge tables). Since I am working on something similar i allways wanted to take a look at it. But I haven't so far ... Maybe this is helpfull for you as well.

janEUcitzen
14th November 2008, 20:00
HI.

thanks a lot, I just had a swift look at the code, and it seems to do the job...at least enough that I can adapt the rest. So now I have some interesting things to do in the weekend.

thanks again
jan