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/doc | |
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/doc')
-rw-r--r-- | examples/qtconcurrent/imagescaling/doc/src/qtconcurrent-imagescaling.qdoc | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/examples/qtconcurrent/imagescaling/doc/src/qtconcurrent-imagescaling.qdoc b/examples/qtconcurrent/imagescaling/doc/src/qtconcurrent-imagescaling.qdoc index a919b7e2ed..8814c826ed 100644 --- a/examples/qtconcurrent/imagescaling/doc/src/qtconcurrent-imagescaling.qdoc +++ b/examples/qtconcurrent/imagescaling/doc/src/qtconcurrent-imagescaling.qdoc @@ -128,23 +128,29 @@ Since the scaling may be computationally heavy, and we don't want to block the main thread, we pass the \c QtFuture::Launch::Async option, to launch the scaling step in - a new thread. + a new thread. The \c scaled() method returns a list of the scaled images to the next + step, which takes care of showing images in the layout. - The \c scaled() method returns a list of the scaled images to the next step, which - takes care of showing images in the layout: + Note that \c updateStatus() is called through QMetaObject::invokeMethod(), + because it updates the UI and needs to be invoked from the main thread. \dots \snippet imagescaling/imagescaling.cpp 5 \dots - Note that showImages() needs to be invoked from the main thread, so we call it through - QMetaObject::invokeMethod(). + For the same reason \c showImages() also needs to be invoked from the main thread, so + we pass \c this as a context to \c .then(). By default, \c .then() is launched in the + parent's thread, but if a context object is specified, it is launched in the context + object's thread. Then we add cancellation and failure handlers: \dots \snippet imagescaling/imagescaling.cpp 6 + We don't need to specify the context anymore, because \c .onCanceled() and the next + handlers will be launched in their parent's context. + The handler attached via the \c .onCanceled() method will be called if the user has pressed the \e "Cancel" button: |