From 29f73f0c9a6fd4172a415d8610178955c67ee6cf Mon Sep 17 00:00:00 2001 From: Dennis Oberst Date: Tue, 28 Feb 2023 14:58:54 +0100 Subject: Example: update imagescaling example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated the example to align with the Qt6 Example-Guideline. https://wiki.qt.io/Qt6/Example-Guideline Task-number: QTBUG-111165 Change-Id: Ibd9e7ce0d4dee90f6a693b81516d2f5b86345b1d Reviewed-by: MÃ¥rten Nordheim (cherry picked from commit b5e9d418959a9d427c14468886470791527e157f) Reviewed-by: Ivan Solovev --- .../imagescaling/doc/images/imagescaling.webp | Bin 0 -> 46826 bytes .../imagescaling/doc/images/imagescaling_example.png | Bin 21049 -> 0 bytes .../imagescaling/doc/src/qtconcurrent-imagescaling.qdoc | 12 ++++++++---- examples/qtconcurrent/imagescaling/imagescaling.cpp | 14 ++++++-------- examples/qtconcurrent/imagescaling/main.cpp | 7 ++++--- 5 files changed, 18 insertions(+), 15 deletions(-) create mode 100644 examples/qtconcurrent/imagescaling/doc/images/imagescaling.webp delete mode 100644 examples/qtconcurrent/imagescaling/doc/images/imagescaling_example.png diff --git a/examples/qtconcurrent/imagescaling/doc/images/imagescaling.webp b/examples/qtconcurrent/imagescaling/doc/images/imagescaling.webp new file mode 100644 index 0000000000..56999faaa7 Binary files /dev/null and b/examples/qtconcurrent/imagescaling/doc/images/imagescaling.webp differ diff --git a/examples/qtconcurrent/imagescaling/doc/images/imagescaling_example.png b/examples/qtconcurrent/imagescaling/doc/images/imagescaling_example.png deleted file mode 100644 index a3860e1974..0000000000 Binary files a/examples/qtconcurrent/imagescaling/doc/images/imagescaling_example.png and /dev/null differ diff --git a/examples/qtconcurrent/imagescaling/doc/src/qtconcurrent-imagescaling.qdoc b/examples/qtconcurrent/imagescaling/doc/src/qtconcurrent-imagescaling.qdoc index f6455c67af..d5008019ee 100644 --- a/examples/qtconcurrent/imagescaling/doc/src/qtconcurrent-imagescaling.qdoc +++ b/examples/qtconcurrent/imagescaling/doc/src/qtconcurrent-imagescaling.qdoc @@ -3,15 +3,17 @@ /*! \example imagescaling - \title Image Scaling Example - \brief Demonstrates how to asynchronously download and scale images. + \meta tags {widgets, threads, network} + \title Image Scaling \ingroup qtconcurrentexamples - \image imagescaling_example.png + \brief Demonstrates how to asynchronously download and scale images. This example shows how to use the QFuture and QPromise classes to download a collection of images from the network and scale them, without blocking the UI. - The application consists of the the following steps: + \image imagescaling.webp + + The application consists of the following steps: \list 1 \li Download images form the list of URLs specified by the user. @@ -148,4 +150,6 @@ The rest of the code is straightforward, you can check the example project for more details. + + \include examples-run.qdocinc */ diff --git a/examples/qtconcurrent/imagescaling/imagescaling.cpp b/examples/qtconcurrent/imagescaling/imagescaling.cpp index 4b19012c04..d674ddd085 100644 --- a/examples/qtconcurrent/imagescaling/imagescaling.cpp +++ b/examples/qtconcurrent/imagescaling/imagescaling.cpp @@ -4,14 +4,12 @@ #include "downloaddialog.h" #include - -#include +#include #include Images::Images(QWidget *parent) : QWidget(parent), downloadDialog(new DownloadDialog(this)) { - setWindowTitle(tr("Image downloading and scaling example")); resize(800, 600); addUrlsButton = new QPushButton(tr("Add URLs")); @@ -90,7 +88,7 @@ void Images::process() // Abort all pending requests abortDownload(); }) - .onFailed([this](const std::exception& ex) { + .onFailed([this](const std::exception &ex) { updateStatus(tr(ex.what())); }); //! [6] @@ -117,7 +115,7 @@ QFuture Images::download(const QList &urls) //! [9] //! [10] - for (auto url : urls) { + for (const auto &url : urls) { QSharedPointer reply(qnam.get(QNetworkRequest(url))); replies.push_back(reply); //! [10] @@ -142,10 +140,10 @@ QFuture Images::download(const QList &urls) promise->finish(); } //! [12] - }).onFailed([=] (QNetworkReply::NetworkError error) { + }).onFailed([promise] (QNetworkReply::NetworkError error) { promise->setException(std::make_exception_ptr(error)); promise->finish(); - }).onFailed([=] { + }).onFailed([promise] { const auto ex = std::make_exception_ptr( std::runtime_error("Unknown error occurred while downloading.")); promise->setException(ex); @@ -164,7 +162,7 @@ QList Images::scaled() const { QList scaled; const auto data = downloadFuture.results(); - for (auto imgData : data) { + for (const auto &imgData : data) { QImage image; image.loadFromData(imgData); if (image.isNull()) diff --git a/examples/qtconcurrent/imagescaling/main.cpp b/examples/qtconcurrent/imagescaling/main.cpp index c7e30df34c..67b543a961 100644 --- a/examples/qtconcurrent/imagescaling/main.cpp +++ b/examples/qtconcurrent/imagescaling/main.cpp @@ -1,15 +1,16 @@ // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -#include -#include - #include "imagescaling.h" +#include int main(int argc, char *argv[]) { QApplication app(argc,argv); + app.setOrganizationName("QtProject"); + app.setApplicationName(QObject::tr("Image Downloading and Scaling")); Images imageView; + imageView.setWindowTitle(QObject::tr("Image Downloading and Scaling")); imageView.show(); return app.exec(); -- cgit v1.2.1