File: qthread.cpp

package info (click to toggle)
qcoro 0.12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,700 kB
  • sloc: cpp: 8,573; python: 32; xml: 26; makefile: 23; sh: 15
file content (17 lines) | stat: -rw-r--r-- 516 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <QCoroThread>
#include <QThread>

#include <memory>

QCoro::Task<void> MainWindow::processData(const QVector<qint64> &data) {
    std::unique_ptr<QThread> thread(QThread::create([data]() {
        // Perform some intesive calculation
    }));
    thread->start();

    ui->setState(tr("Processing is starting..."));
    co_await qCoro(thread.get()).waitForStarted();
    ui->setState(tr("Processing data..."));
    co_await qCoro(thread.get()).waitForFinished();
    ui->setState(tr("Processing done."));
}