PDA

View Full Version : Progress of SQL "select"



brokensword
11th January 2008, 23:09
Is there any nice way of receiving info about progress of "select" statement in qt?
First step looks clear: select count().... and use it as 100%. But what's next? Determining size of one record? Very dirty way...

jacek
11th January 2008, 23:19
What would you need the record's size for? SELECT COUNT() and QSqlQuery::size() return the number of records --- each of them counts as 1.

Just remember that if you want to display that progress, you have to let Qt process events from time to time.

brokensword
12th January 2008, 09:59
The question is: which events Qt should process from time to time?

jacek
12th January 2008, 14:29
Just invoke QCoreApplication::processEvents() with default parameter or with QEventLoop::ExcludeUserInputEvents.

brokensword
14th January 2008, 11:00
Sorry, I can't understand your idea. Select() function is synchronous, it doesn't return until all data would be fetched. So where from should I call processEvents()?

Can you give some piece of example code?

jacek
14th January 2008, 16:37
Select() function is synchronous, it doesn't return until all data would be fetched.
I see we don't understand each other. Please define "progress of select statement".

brokensword
14th January 2008, 17:24
I have a QSqlTableModel. I fill it with data using setFilter() or select() methods of QSqlTableModel. Both are synchronous (they don't return until all records would be fetched). Operation can take more then 5 minutes.

Everything I need to know is just how much records were fetched so far.

I've tried to make static QSqlTableModel object, fill it with data in separate thread and call rowsCount() (query->size()) in loop in main thread. It doesn't helps - rowsCount() (and query->size)) return 0 until model would be fully filled.

So is there any way to get QSqlTableModel filling progress info?

jacek
14th January 2008, 17:29
Everything I need to know is just how much records were fetched so far.
I see, I thought you were using QSqlQuery.

You might try connecting to QAbstractItemModel::rowsInserted() signal.

brokensword
15th January 2008, 10:25
Didn't work. rowsInserted() signal is emmited only once - at the end of filling process.


I see, I thought you were using QSqlQuery.

You might try connecting to QAbstractItemModel::rowsInserted() signal.

jacek
16th January 2008, 16:40
Didn't work. rowsInserted() signal is emmited only once - at the end of filling process.
Too bad. I've checked the sources and it looks like QSqlTableModel (QSqlQueryModel actually) doesn't fetch the data row-by-row, but rather retrieves particular cells as needed in data() using QSqlQuery::seek().

Maybe you could create your own model that will load data using typical while( query.next() ) loop?