The program performs many calculations in the database (first, the source table is divided into subtables, after which some fields are calculated in each subtable and another common table is created based on all subtables). All at the level of SQL queries. I want to display the progress of these calculations.
Is there any way to do this?

Here is the code that performs the calculations, if someone comes in handy;

  • You need to somehow "notify". The easiest way is to break up requests into small ones and execute each one individually, and not all in one ensemble. Then everything will be easy. - KoVadim
  • You have a while(_query.next()) . Before him, count the total number of results, inside the cycle, display the progress. - arrowd
  • only if there are more than a hundred or two records, then it is not necessary to update the progress at each iteration. Otherwise it can be very long. - KoVadim

2 answers 2

Add a signal

 void progressChanged(int); 

And change the function so

 void DataBase::initDataBase() { createMainTable(); QSqlQuery _query(db); QString str_query = "SELECT DISTINCT client FROM input_data"; if(_query.exec(str_query)) { int percent = 0; int i = 0; int size = _query.size(); emit progressChanged(percent); while(_query.next()) { QString client = _query.value("client").toString(); createClientTable(client); initClientTable(client); addTupleInMainTable(client); i++; int currentPercent = (int)((double)i/size) * 100); if(percent != currentPercent) { percent != currentPercent; emit progressChanged(percent); } } } else qDebug() << "База данных | Ошибка выгружения уникальных клиентов"; } 

The signal will be triggered only by a percentage change, not every time the counter changes.

  • int currentPercent = (int)((double)i/size) * 100); You can replace this variant int currentPercent = 100 * i /size; changing the order of arithmetic operations will eliminate the need to do type conversions. - Kirill

If everything is done in one request without returning control, this information is available only from the DBMS. However, by query.next() you can. You can use QtConcurrentRun::mappedReduced and return QFuture , the amount of progress that can be polled. somewhere were the standard examples for this