Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void DimexReportsProcessor::countRows(const QString &databaseName, std::function<void(void)> onStart, std::function<void(long long)> onDone)
- {
- auto watcher = getWatcher();
- watchers_ << watcher;
- connect(watcher, &Watcher::finished, [this, watcher, databaseName, onDone]()
- {
- QVariantMap result = watcher->future().result();
- if (result["job"].toString().compare("count") == 0)
- {
- long long rowsCount = result["count"].toLongLong();
- onDone(rowsCount);
- }
- freeWatchers_ << watcher;
- watchers_.removeAll(watcher);
- watcher->disconnect();
- });
- onStart();
- watcher->setFuture(QtConcurrent::run([databaseName, this]() -> QVariantMap
- {
- QVariantMap result;
- QString query = loadQuery("totalrowsnumberquery");
- soci::session sql(soci::firebird, QString("service=%1 user=SYSDBA password=masterkey").arg(databaseName).toStdString());
- long long count = 0;
- sql << query.toStdString(), soci::into(count);
- result["job"] = QString("count");
- result["count"] = count;
- return result;
- }));
- }
- .........
- connect(ui->openButton, &QPushButton::clicked, [this]
- {
- QString fileName = QFileDialog::getOpenFileName(this, trUtf8("Select database files"), "", trUtf8("Firebird database files (*.fdb)"));
- if (!fileName.isNull())
- {
- qDebug() << fileName;
- processor_->countRows(fileName, [this, fileName]
- {
- ui->exportButton->setEnabled(false);
- ......
- },
- [this, fileName](long long rowsCount)
- {
- ui->rowsCountLabel->setText(trUtf8("[Rows count: <b style='color:green'>%1</b>]").arg(rowsCount));
- openedDataBaseName_ = fileName;
- ui->exportButton->setEnabled(true);
- });
- }
- else
- {
- .....
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement