Fix QPromise snippets: use QScopePointer instead of QPointer
Change-Id: I2b863e43eb227a80ded3422ca57bd5f5d4209858 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
parent
967f2fbfad
commit
afd34d74b8
@ -58,7 +58,7 @@
|
|||||||
#include <qfuture.h>
|
#include <qfuture.h>
|
||||||
#include <qfuturewatcher.h>
|
#include <qfuturewatcher.h>
|
||||||
#include <qpromise.h>
|
#include <qpromise.h>
|
||||||
#include <qpointer.h>
|
#include <qscopedpointer.h>
|
||||||
#include <qsharedpointer.h>
|
#include <qsharedpointer.h>
|
||||||
|
|
||||||
class snippet_QPromise
|
class snippet_QPromise
|
||||||
@ -79,7 +79,7 @@ void snippet_QPromise::basicExample()
|
|||||||
// of calls: first promise.reportStarted() then future.waitForFinished()
|
// of calls: first promise.reportStarted() then future.waitForFinished()
|
||||||
promise.reportStarted(); // notifies QFuture that the computation is started
|
promise.reportStarted(); // notifies QFuture that the computation is started
|
||||||
|
|
||||||
QPointer<QThread> thread(QThread::create([] (QPromise<int> promise) {
|
QScopedPointer<QThread> thread(QThread::create([] (QPromise<int> promise) {
|
||||||
promise.addResult(42);
|
promise.addResult(42);
|
||||||
promise.reportFinished(); // notifies QFuture that the computation is finished
|
promise.reportFinished(); // notifies QFuture that the computation is finished
|
||||||
}, std::move(promise)));
|
}, std::move(promise)));
|
||||||
@ -106,14 +106,14 @@ void snippet_QPromise::multithreadExample()
|
|||||||
|
|
||||||
//! [multithread_main]
|
//! [multithread_main]
|
||||||
// here, QPromise is shared between threads via a smart pointer
|
// here, QPromise is shared between threads via a smart pointer
|
||||||
QPointer<QThread> threads[] = {
|
QScopedPointer<QThread> threads[] = {
|
||||||
QPointer<QThread>(QThread::create([] (auto sharedPromise) {
|
QScopedPointer<QThread>(QThread::create([] (auto sharedPromise) {
|
||||||
sharedPromise->addResult(0, 0); // adds value 0 by index 0
|
sharedPromise->addResult(0, 0); // adds value 0 by index 0
|
||||||
}, sharedPromise)),
|
}, sharedPromise)),
|
||||||
QPointer<QThread>(QThread::create([] (auto sharedPromise) {
|
QScopedPointer<QThread>(QThread::create([] (auto sharedPromise) {
|
||||||
sharedPromise->addResult(-1, 1); // adds value -1 by index 1
|
sharedPromise->addResult(-1, 1); // adds value -1 by index 1
|
||||||
}, sharedPromise)),
|
}, sharedPromise)),
|
||||||
QPointer<QThread>(QThread::create([] (auto sharedPromise) {
|
QScopedPointer<QThread>(QThread::create([] (auto sharedPromise) {
|
||||||
sharedPromise->addResult(-2, 2); // adds value -2 by index 2
|
sharedPromise->addResult(-2, 2); // adds value -2 by index 2
|
||||||
}, sharedPromise)),
|
}, sharedPromise)),
|
||||||
// ...
|
// ...
|
||||||
@ -147,7 +147,7 @@ void snippet_QPromise::suspendExample()
|
|||||||
|
|
||||||
promise.reportStarted();
|
promise.reportStarted();
|
||||||
// Start a computation thread that supports suspension and cancellation
|
// Start a computation thread that supports suspension and cancellation
|
||||||
QPointer<QThread> thread(QThread::create([] (QPromise<int> promise) {
|
QScopedPointer<QThread> thread(QThread::create([] (QPromise<int> promise) {
|
||||||
for (int i = 0; i < 100; ++i) {
|
for (int i = 0; i < 100; ++i) {
|
||||||
promise.addResult(i);
|
promise.addResult(i);
|
||||||
promise.suspendIfRequested(); // support suspension
|
promise.suspendIfRequested(); // support suspension
|
||||||
|
Loading…
Reference in New Issue
Block a user