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...
Printable View
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...
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.
The question is: which events Qt should process from time to time?
Just invoke QCoreApplication::processEvents() with default parameter or with QEventLoop::ExcludeUserInputEvents.
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?
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?
I see, I thought you were using QSqlQuery.
You might try connecting to QAbstractItemModel::rowsInserted() signal.
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?