From c7771366e5dc8328e235f0a7056345ac25a16883 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 1 Nov 2024 11:09:07 +0100 Subject: [PATCH] [docs] QPromise: don't recommend legacy smart pointers Use unique_ptr instead of QScopedPointer and shared_ptr instead of QSharedPointer. Amends 68de38ded1c0e5387ae29aacaee50ba5dacfc59a. Pick-to: 6.5 6.2 Change-Id: Ic5c4c4962be69aecd4312dbdbfa84deb8a3c1e57 Reviewed-by: Ivan Solovev (cherry picked from commit 076445ec0d888f74498b4beadced58edce434ee9) Reviewed-by: Qt Cherry-pick Bot --- .../thread/qpromise/snippet_qpromise.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/auto/corelib/thread/qpromise/snippet_qpromise.cpp b/tests/auto/corelib/thread/qpromise/snippet_qpromise.cpp index 2cef0dca959..2a9ee430cd8 100644 --- a/tests/auto/corelib/thread/qpromise/snippet_qpromise.cpp +++ b/tests/auto/corelib/thread/qpromise/snippet_qpromise.cpp @@ -11,8 +11,8 @@ #include #include #include -#include -#include + +#include class snippet_QPromise { @@ -29,7 +29,7 @@ void snippet_QPromise::basicExample() QPromise promise; QFuture future = promise.future(); - QScopedPointer thread(QThread::create([] (QPromise promise) { + const std::unique_ptr thread(QThread::create([] (QPromise promise) { promise.start(); // notifies QFuture that the computation is started promise.addResult(42); promise.finish(); // notifies QFuture that the computation is finished @@ -49,7 +49,7 @@ void snippet_QPromise::multithreadExample() { #if QT_CONFIG(cxx11_future) //! [multithread_init] - QSharedPointer> sharedPromise(new QPromise()); + const auto sharedPromise = std::make_shared>(); QFuture future = sharedPromise->future(); // ... @@ -59,14 +59,14 @@ void snippet_QPromise::multithreadExample() //! [multithread_main] // here, QPromise is shared between threads via a smart pointer - QScopedPointer threads[] = { - QScopedPointer(QThread::create([] (auto sharedPromise) { + const std::unique_ptr threads[] = { + std::unique_ptr(QThread::create([] (auto sharedPromise) { sharedPromise->addResult(0, 0); // adds value 0 by index 0 }, sharedPromise)), - QScopedPointer(QThread::create([] (auto sharedPromise) { + std::unique_ptr(QThread::create([] (auto sharedPromise) { sharedPromise->addResult(-1, 1); // adds value -1 by index 1 }, sharedPromise)), - QScopedPointer(QThread::create([] (auto sharedPromise) { + std::unique_ptr(QThread::create([] (auto sharedPromise) { sharedPromise->addResult(-2, 2); // adds value -2 by index 2 }, sharedPromise)), // ... @@ -104,7 +104,7 @@ void snippet_QPromise::suspendExample() promise.start(); // Start a computation thread that supports suspension and cancellation - QScopedPointer thread(QThread::create([] (QPromise promise) { + const std::unique_ptr thread(QThread::create([] (QPromise promise) { for (int i = 0; i < 100; ++i) { promise.addResult(i); promise.suspendIfRequested(); // support suspension