qt5base-lts/examples/qtconcurrent/imagescaling
Ivan Solovev 5ddb5d1fee Rework imagescaling example to avoid potential crashes
Creating a continuation with QtFuture::Launch::Async policy does not
work well with the example, because it still needs to update the UI
once the async continuation is finished. If the user decides to
close the application while the async continuation is executed,
the next continuation will be accessing data from the destroyed
Images object.

Fix it by using QtConcurrent::run() to do the "heavy" work in a
separate thread, and use a QFutureWatcher to handle the results of
the async execution. Update the example documentation accordingly.

After this patch the example still shows the usage of continuations
and onCanceled()/onFailed() handlers. However, it now does not
illustrate the usage of different launch policies and continuation
contexts. It might not be a big issue, because the QFuture
documentation describes these topics rather extensively.

Fixes: QTBUG-103514
Pick-to: 6.5
Change-Id: I8142535064ff7a4e8007a5c0a8fe7709d6d942ec
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2023-04-26 19:27:30 +02:00
..
doc Rework imagescaling example to avoid potential crashes 2023-04-26 19:27:30 +02:00
CMakeLists.txt Examples: Use PRIVATE CMake linkage 2022-11-30 14:48:50 +01:00
downloaddialog.cpp Use SPDX license identifiers 2022-05-16 16:37:38 +02:00
downloaddialog.h Use SPDX license identifiers 2022-05-16 16:37:38 +02:00
downloaddialog.ui Improve QtConcurrent ImageScaling example to demo new features 2020-11-12 08:56:14 +01:00
imagescaling.cpp Rework imagescaling example to avoid potential crashes 2023-04-26 19:27:30 +02:00
imagescaling.h Rework imagescaling example to avoid potential crashes 2023-04-26 19:27:30 +02:00
imagescaling.pro Improve QtConcurrent ImageScaling example to demo new features 2020-11-12 08:56:14 +01:00
main.cpp Example: update imagescaling example 2023-03-09 17:26:59 +00:00