summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/snippets
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2020-12-04 17:20:29 +0100
committerSona Kurazyan <sona.kurazyan@qt.io>2020-12-11 09:36:45 +0100
commit335acffe1d955b5fe4535dc1d99ec2c3dbe1b978 (patch)
tree4648a3814a956bbe5d0dc8c39bf4f120ce30c591 /src/corelib/doc/snippets
parentb283ce1e836ab08e602a11ea255ee3d8e537902e (diff)
Add support of invoking QFuture continuations in a given context
Added overloads of .then()/.onFailed()/.onCanceled() which take a pointer of a context object, and invoke the continuations in the object's thread. Task-number: QTBUG-86794 Change-Id: I0f3cbb0500695673fc4087af5d4b96b416e3e1ce Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Diffstat (limited to 'src/corelib/doc/snippets')
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_thread_qfuture.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_thread_qfuture.cpp b/src/corelib/doc/snippets/code/src_corelib_thread_qfuture.cpp
index da17b390fd..a5e1a7f6e4 100644
--- a/src/corelib/doc/snippets/code/src_corelib_thread_qfuture.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_thread_qfuture.cpp
@@ -252,3 +252,34 @@ auto resultFuture = testFuture.then([](int res) {
// Block 6
});
//! [16]
+
+//! [17]
+// somewhere in the main thread
+auto future = QtConcurrent::run([] {
+ // This will run in a separate thread
+ ...
+}).then(this, [] {
+ // Update UI elements
+});
+//! [17]
+
+//! [18]
+auto future = QtConcurrent::run([] {
+ ...
+}).then(this, [] {
+ // Update UI elements
+}).then([] {
+ // This will also run in the main thread
+});
+//! [18]
+
+//! [19]
+// somewhere in the main thread
+auto future = QtConcurrent::run([] {
+ // This will run in a separate thread
+ ...
+ throw std::exception();
+}).onFailed(this, [] {
+ // Update UI elements
+});
+//! [19]