Performance of Using QSqlTableModel
Hi,
I use QSqlTableModel to access table stored in database,when I traverse and handle every row in one table which contains about 3500 rows, i find it need 3-4 seconds that is too slow. Is it normal and how to improve it?
here is my code,
Code:
int GetRecordCount()ï½›
while(sqlTableModel.canFetchMore())
ï½›
sqlTableModel.fetchMore();
ï½
return sqlTableModel.rowCount();
ï½
//traverse table
for (i=0 ï¼›i<=GetRecordCount()ï¼›i++)
ï½›
//...
//...
ï½
Re: Performance of Using QSqlTableModel
Have you tried without the model overhead, i.e. using QSqlQuery, as suggested in the other thread?
Cheers,
_
Re: Performance of Using QSqlTableModel
Quote:
Originally Posted by
anda_skoa
Have you tried without the model overhead, i.e. using QSqlQuery, as suggested in the other thread?
Cheers,
_
Thanks first!
I have tried using QSqlQuery as follows, but it was still very slow (need 5s to traverse about 3000 rows ), so why? Any ideas or suggestions?
Code:
while (query.next()) {
doSomething();
}
Re: Performance of Using QSqlTableModel
What is "doSomething()" doing ?
Re: Performance of Using QSqlTableModel
Quote:
Originally Posted by
stampede
What is "doSomething()" doing ?
let's say as follows,
Code:
void doSomething()
{
i++;
}
so this mean that the "while" loop need too much time to execute itself. Now i notice that tableA has a field which store blob, once i don't select this field, then the speed become fast! Why and how to deal with blob with QSqlTableModel?
thanks!
Re: Performance of Using QSqlTableModel
BLOB is just a collection of bytes, it could be anything (for example image data), and it is up to the application to interpret it correctly. Looks like in your case it is quite large, so it affects the performance of your queries.
Re: Performance of Using QSqlTableModel
BLOBS are presented by Qt as a QVariant::ByteArray.