PDA

View Full Version : Performance of Using QSqlTableModel



silentyears
14th February 2014, 10:14
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,


int GetRecordCount()ï½›
while(sqlTableModel.canFetchMore())
ï½›
sqlTableModel.fetchMore();
}
return sqlTableModel.rowCount();
}

//traverse table
for (i=0 ï¼›i<=GetRecordCount()ï¼›i++)
ï½›
QSqlRecord record = sqlTableModel.record(i);
//...
//...
}

anda_skoa
14th February 2014, 11:52
Have you tried without the model overhead, i.e. using QSqlQuery, as suggested in the other thread?

Cheers,
_

silentyears
17th February 2014, 13:41
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?



QSqlQuery query("SELECT * FROM tableA");
while (query.next()) {
doSomething();
}

stampede
17th February 2014, 14:09
What is "doSomething()" doing ?

silentyears
18th February 2014, 15:13
What is "doSomething()" doing ?

let's say as follows,


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!

stampede
18th February 2014, 18:59
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.

ChrisW67
19th February 2014, 00:37
BLOBS are presented by Qt as a QVariant::ByteArray.