diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2020-12-08 17:42:12 +0100 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2020-12-11 11:45:45 +0100 |
commit | 81ed78c2936d569daa85bf5dcface076a36d6f2b (patch) | |
tree | 5a39ade081c75151bf77308ce57b3fddaaed059a /examples/qtconcurrent/imagescaling/imagescaling.cpp | |
parent | f8f955151a6a218e1d274663c7c309b8eb6ca92a (diff) |
Improve the QtConcurrent ImageScaling example
Provide execution context to QFuture continuations, instead of using
QMetaObject::invokeMethod calls for running in the main thread.
Change-Id: Ica7de19494065d677ffc94224781bfbe292b4f21
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'examples/qtconcurrent/imagescaling/imagescaling.cpp')
-rw-r--r-- | examples/qtconcurrent/imagescaling/imagescaling.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/examples/qtconcurrent/imagescaling/imagescaling.cpp b/examples/qtconcurrent/imagescaling/imagescaling.cpp index 59664f8a58..66bb0686c3 100644 --- a/examples/qtconcurrent/imagescaling/imagescaling.cpp +++ b/examples/qtconcurrent/imagescaling/imagescaling.cpp @@ -118,24 +118,24 @@ void Images::process() downloadFuture.then([this](auto) { cancelButton->setEnabled(false); }) .then(QtFuture::Launch::Async, [this] { - updateStatus(tr("Scaling...")); + QMetaObject::invokeMethod(this, + [this] { updateStatus(tr("Scaling...")); }); return scaled(); }) //! [4] //! [5] - .then([this](const QList<QImage> &scaled) { - QMetaObject::invokeMethod(this, [this, scaled] { showImages(scaled); }); + .then(this, [this](const QList<QImage> &scaled) { + showImages(scaled); updateStatus(tr("Finished")); }) //! [5] //! [6] .onCanceled([this] { updateStatus(tr("Download has been canceled.")); }) .onFailed([this](QNetworkReply::NetworkError error) { - const auto msg = QString("Download finished with error: %1").arg(error); - updateStatus(tr(msg.toStdString().c_str())); + updateStatus(tr("Download finished with error: %1").arg(error)); // Abort all pending requests - QMetaObject::invokeMethod(this, &Images::abortDownload); + abortDownload(); }) .onFailed([this](const std::exception& ex) { updateStatus(tr(ex.what())); @@ -256,7 +256,7 @@ void Images::initLayout(qsizetype count) void Images::updateStatus(const QString &msg) { - QMetaObject::invokeMethod(this, [this, msg] { statusBar->showMessage(msg); }); + statusBar->showMessage(msg); } void Images::abortDownload() |