Commit Graph

97 Commits

Author SHA1 Message Date
Safiyyah Moosa
a1d308a316 Doc: Add \examplecategory for qtconcurrent
Task-number: QTBUG-116071
Pick-to: 6.5 6.6
Change-Id: I7413a0d8085eec38e6480f6aa21c85620ca68f54
Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
2023-09-07 15:05:04 +02:00
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
Dennis Oberst
8352756d27 Example: rename progressdialog to primecounter and modernize it
The previous example finished way too quickly and provided no real
value in regards to API understanding. Previously, QtConcurrent::map
was used, which was also used in other examples. We are now using
QtConcurrent::filterReduce to demonstrate other functionality.

Task-number: QTBUG-111165
Pick-to: 6.5 6.5.0
Change-Id: Ibd6eb119d0711cddfe8b211d460e9d67d6ce95c3
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-03-21 11:19:42 +01:00
Dennis Oberst
d795dfaee7 Example: update wordcount example
Added a QFileDialog to let the user select a path. Before, the path
was statically assigned with "../../" , which is not optimal.
I also modified the findFiles function to check for text files in
general and not only *.cpp and *.h files. Lastly the result of the
word counting is now displayed on the console, as I think this is an
informative output from this example.

Task-number: QTBUG-111165
Pick-to: 6.5 6.5.0
Change-Id: Ie27c6acb4f79a78e3bef141edb92de08901fde71
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-03-20 20:58:08 +01:00
Ivan Solovev
0ac234f9e2 Imagescaling example: fix memory leaks
* The DownloadDialog was never destroyed properly. Pass 'this' to its
  constructor to fix it.
* When re-creating an image grid layout, properly clean up old image
  labels in Images::initLayout()

Task-number: QTBUG-103514
Pick-to: 6.5 6.5.0
Change-Id: Ief52774002632d4ad3a6cca85bb0c0aa1a1d4bc0
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2023-03-13 19:24:14 +01:00
Dennis Oberst
de5e0422ca Example: remove runfunction example
This example shows how to use QtConcurrent::run by calling a global
function and printing the thread ID. As the documentation already
explains the functionality very well, I don't think this example is
necessary.

https://doc.qt.io/qt-6/qtconcurrentrun.html

Task-number: QTBUG-111165
Pick-to: 6.5 6.5.0
Change-Id: I42a718cdaabdaeeab39b933d12c67d11978c95da
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-03-09 17:26:59 +00:00
Dennis Oberst
fbb470b40b Example: remove map example
This example only demonstrates the use of blockingMapped. Considering
that the QtConcurrent::mapped~ functions are already included in the
wordcount example, and have very similar APIs to the
QtConcurrent::filter~ functions, which are included in the
progressdialog example, this no longer serves a useful purpose.

Task-number: QTBUG-111165
Pick-to: 6.5 6.5.0
Change-Id: Ibc526e1a9fb17070e376e45151e9c2bdbc69bd32
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-03-09 17:26:59 +00:00
Dennis Oberst
b5e9d41895 Example: update imagescaling example
Updated the example to align with the Qt6 Example-Guideline.

https://wiki.qt.io/Qt6/Example-Guideline

Task-number: QTBUG-111165
Pick-to: 6.5 6.5.0
Change-Id: Ibd9e7ce0d4dee90f6a693b81516d2f5b86345b1d
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-03-09 17:26:59 +00:00
Andreas Eliasson
8ecd81ae86 Doc: Remove duplicate words
Change-Id: Ia7a38a1035bd34d00f20351a0adc3927e473b2e7
Pick-to: 6.5 6.4 6.2
Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
2023-02-28 16:53:10 +00:00
Kai Köhne
a5de12f0d7 Examples: Use PRIVATE CMake linkage
We (almost) only build apps, for which PRIVATE linkage makes more sense.

Change-Id: I09a509c3fb33a00cdfdede687b3f95d638f42091
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-11-30 14:48:50 +01:00
Kai Köhne
f562711c64 Examples: Use qt_standard_project_setup()
Change-Id: I0ceab08108b7e58e4e2ed25db9e3c289f5c0ddac
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-11-17 19:59:11 +01:00
Kai Köhne
bec264c15f Examples: Use Qt6:: to qualify Qt CMake packages
This is what we promote also in the documentation.

Change-Id: If91aebafe861b0c934acbb2c69afd182abc3345d
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-11-17 19:59:11 +01:00
Lucie Gérard
32df595275 Change the license of all CMakeLists.txt and *.cmake files to BSD
Task-number: QTBUG-105718
Change-Id: I5d3ef70a31235868b9be6cb479b7621bf2a8ba39
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-08-23 23:58:42 +02:00
Lucie Gérard
fb1b20eab3 Add license headers to cmake files
CMakeLists.txt and .cmake files of significant size
(more than 2 lines according to our check in tst_license.pl)
now have the copyright and license header.

Existing copyright statements remain intact

Task-number: QTBUG-88621
Change-Id: I3b98cdc55ead806ec81ce09af9271f9b95af97fa
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-08-03 17:14:55 +02:00
Lucie Gérard
05fc3aef53 Use SPDX license identifiers
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
Files that have to be modified by hand are modified.
License files are organized under LICENSES directory.

Task-number: QTBUG-67283
Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-05-16 16:37:38 +02:00
Kai Köhne
57402ffb9b Examples: Remove unneeded CMake options
CMAKE_INCLUDE_CURRENT_DIR is not necessary anymore for moc since
CMake 3.8: https://cmake.org/cmake/help/latest/release/3.8.html#other-changes

CMAKE_AUTORCC should not be used anymore. Instead, we now use
qt_add_resources() or similar

Enable CMAKE_AUTOUIC only if .ui files are present.

Pick-to: 6.3
Task-number: QTBUG-87643
Change-Id: I835e2994cd5dba9918136999499b9077961b616c
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-01-24 14:00:00 +01:00
Kai Köhne
131681652e Examples: Clean up WIN32_EXECUTABLE, MACOSX_BUNDLE properties
Both are FALSE by default, so no point in explicitly setting
them to FALSE.

In addition, dbus/listnames is a command line tool. No reason
to set WIN32_EXECUTABLE, MACOSX_BUNDLE here.

Pick-to: 6.3
Change-Id: I99aaf27a0267c5575bd2ee5b6183991fce721f44
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-12-17 10:38:49 +01:00
Kai Köhne
80a76df178 Examples: Fix whitespace issues in CMakeLists.txt
Pick-to: 6.3
Change-Id: I8e6dd1f250f8be6016ee4164cb2ab7034cbb1203
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-12-13 14:16:26 +00:00
Kai Köhne
51f22a3a04 Examples: Remove remaining conversion markers in CMakeLists.txt
Pick-to: 6.3
Change-Id: Ia5d474a3efd6aadbd0ef1537318f2f24e6c24fee
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-12-13 14:16:26 +00:00
Kai Köhne
7024e7a627 Examples: Use find_package(Qt6 REQUIRED COMPONENTS ...) idiom
Also consolidate several find_package(Qt6 ...) calls in one call.

Task-number: QTBUG-98867
Change-Id: Idfd5e71f46d4489fac7411cbfadb84437a0658f3
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2021-12-10 10:48:26 +01:00
Kai Köhne
251e848007 Remove .prev_CMakeLists.txt
These are left-overs from the initial qmake2cmake conversion.

Pick-to: 6.2
Change-Id: Ie15c9ff022ea4566d10c1ba74599de9af83d29a7
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-12-06 11:23:26 +00:00
Joerg Bornemann
ff00ef6410 Raise cmake_minimum_required to VERSION 3.16 in examples
Pick-to: 6.2
Task-number: QTBUG-95636
Change-Id: I1270b4846d8a23bc3563b6942c0910e095d2be4a
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-08-17 19:18:54 +02:00
Craig Scott
d97fd7af2b Build examples in isolated sub-builds using ExternalProject
Examples are intended to show how to build against an installed Qt.
Building them as part of the main build means the way the Qt targets
are defined and created are not representative of an end user's build.
By building them as separate projects using ExternalProject, we can
more closely replicate the intended audience's environment. This
should allow us to catch more problems earlier.

Having examples built as part of the main build also creates problems
with some static builds where a tool built by the main build is needed
during configure time. This happens with other repos like qtdeclarative
but not (currently) with qtbase. Converting the examples in qtbase to
be built using ExternalProject is intended as a demonstrator for how
other repos can do similar. Until other repos are converted, they will
continue to work as they did before, with examples as part of the main
build for non-static builds only.

The new build-externally behavior is only supported for non-prefix
builds with this change. Prefix builds will continue to use the old
non-external method. Support for building examples externally in
prefix builds will be a separate change.

Task-number: QTBUG-90820
Fixes: QTBUG-91068
Change-Id: I2304329940568dbdb7da18d54d5595ea7d8668bc
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2021-05-26 13:33:29 +02:00
Sona Kurazyan
81ed78c293 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>
2020-12-11 11:45:45 +01:00
Sona Kurazyan
190b77463d Improve QtConcurrent ImageScaling example to demo new features
In order to demonstrate the new functionality, changed the example to
download the images from the network, scale and show them by attaching
different continuations to QFuture. Because QtConcurrent::map is not
used anymore, removed the suspension functionality (supporting
suspension of download would complicate the logic).

Task-number: QTBUG-87205
Change-Id: I5a48b63195d28025ae8c5de28bc6d6178dad03db
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2020-11-12 08:56:14 +01:00
Sona Kurazyan
ff0ba7e2d7 Forbid implicit conversions between QFuture and other types
- Remove the casting operator of QFuture<T> to T. It calls
  QFuture::result(), which may lead to undefined behavior if the user
  has moved the results from QFuture via QFuture::takeResult() before
  trying to do the conversion.

- Disable implicit conversion of QFuture<T> to QFuture<void>, by making
  the constructor explicit. If the users really intend to do the
  conversion, they should do it explicitly.

[ChangeLog][Source-Incompatible Changes][QFuture] Implicit conversions
of QFuture<T> to T and to QFuture<void> have been disabled. Use
QFuture::result() or QFuture::takeResult() where you need to convert
QFuture<T> to T. Use the explicit QFuture<void>(const QFuture<T> &)
constructor to convert QFuture<T> to QFuture<void>.

Change-Id: I153d4137d36365b1611ac934fb3ac2eb667fdd6c
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2020-10-30 17:19:26 +01:00
Alexandru Croitor
397b372517 CMake: Regenerate examples to set the WIN32_EXECUTABLE property
As well as the MACOSX_BUNDLE properties as necessary.

Task-number: QTBUG-87664
Task-number: QTBUG-86827
Change-Id: I7677449a26d51fa853bd67bab6b3b61afbd2b12f
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2020-10-27 12:49:39 +01:00
Alexandru Croitor
2ffbac7cb2 CMake: Regenerate examples to use qt_add_executable
Task-number: QTBUG-87661
Change-Id: I0dacfdc97a3fb7d88da85b67800f2c1b084d869b
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2020-10-19 11:51:47 +02:00
Alexandru Croitor
74cb331af3 CMake: Regenerate examples
Change-Id: I1c51b10af4e2b26f54740f257164c56a0e2a03ce
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2020-07-09 09:38:28 +02:00
Tor Arne Vestbø
46d4c2022d Fix warnings in QtConcurrent image scaling example
Change-Id: Ib82b2abf608536ef4df6d7cfa5fb106f29f9253f
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2020-07-01 14:57:43 +02:00
Jarek Kobus
29c99bddbf Use QList instead of QVector in examples
Task-number: QTBUG-84469
Change-Id: Id14119168bb1bf11f99bda7ef6ee9cf51bcfab2e
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
2020-06-23 14:01:11 +02:00
Karsten Heimrich
b251d6137d Fix examples build after a061a64642
Change-Id: I4d10b4439e5a858437751b00efde2bf8c467e857
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2020-06-17 22:40:02 +02:00
Shawn Rutledge
a061a64642 Replace calls to deprecated QEvent accessor functions
Many of these were generated by clazy using the new qevent-accessors check.

Change-Id: Ie17af17f50fdc9f47d7859d267c14568cc350fd0
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2020-06-08 19:11:51 +02:00
Alexandru Croitor
7610805879 Regenerate examples
Change-Id: I04b2adbe370ffea81d7787ad90e4ae69d2c165cb
Reviewed-by: Qt CMake Build Bot
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2020-02-04 18:50:39 +00:00
Alexandru Croitor
4dac45c9ee Merge remote-tracking branch 'origin/wip/qt6' into wip/cmake
Change-Id: I715b1d743d5f11560e7b3fbeb8fd64a5e5ddb277
2019-07-11 17:17:51 +02:00
Alexandru Croitor
fe3bd212fc Merge remote-tracking branch 'origin/wip/qt6' into wip/cmake
This changes many different CMake places to mention Qt6 instead of
Qt5.

Note that some old qt5 cmake config files in corelib are probably not
needed anymore, but I still renamed and kept them for now.

Change-Id: Ie69e81540386a5af153f76c0242e18d48211bec4
2019-06-14 16:31:09 +02:00
Simon Hausmann
efa9998521 Fix compiling of examples on Android
* Simplify add_qt_gui_executable() to not require WIN32/MACOSX_BUNDLE
  but provide it implicitly. It's redundant :)

* When on Android, build a module (shared library), just like qmake.
  This requires an additional library destination in the install() call,
  but that's ignored on other platforms.

* Fix typos in the android deployment generation settings function

* Use the correct cache variable to determine whether we're inside a Qt
  build or not. Right now this only works inside Qt builds anyway as
  QtPlatformAndroid.cmake is not publically accessible.

Change-Id: If1c763c31a7a83d0e0d854362ba7901657f63eb5
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Qt CMake Build Bot
2019-06-12 14:19:53 +00:00
Simon Hausmann
6732fa3a29 Fix linking of examples
Provide add_qt_gui_executable() as function in our public API that takes
care of automaticWinMain linkage. We can use this in the future to
encapsulate similarplatform-specific behavior and adjustments, such as
module generation onAndroid.

In order for the examples to see the function in Qt5CoreMacros, three more
additional fixes were required:

    * Do the build_repo_end() call _before_ attempting to build the
      examples, as we need the build_repo_end() to include QtPostProcess
      and complete the creation of all the target config files.
      Otherwise the find_package() calls in the examples see something
      incomplete.

    * Add more QT_NO_CREATE_TARGET guards

    * Always call find_dependency on the dependencies, regardless of the
      target creation mode. This way a find_package(Qt5 COMPONENTS
      Widgets) will still load Qt5CoreMacros.

Change-Id: I03ce856e2f4312a050fe8043b8331cbe8a6c93e6
Reviewed-by: Qt CMake Build Bot
Reviewed-by: Leander Beernaert <leander.beernaert@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-06-12 14:19:34 +00:00
Kevin Funk
99539a2894 Allow to build examples as standalone project
Create CMake config files which can be used from the very same CMake
project. These CMake config files simply do not create any targets,
controlled via the QT_NO_CREATE_TARGETS.

This patch also allows to build qtbase.git:examples as a standalone
project, against an already-built Qt.

Ran this:
  ag -s "QT " examples -l -0 | xargs -0 -n 1 .../util/cmake/pro2cmake.py --is-example

Task-number: QTBUG-74713
Change-Id: I44cce5a4048618b30f890c5b789592c227a8b47d
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-06-05 12:53:28 +00:00
Alexandru Croitor
e4079eca49 Merge remote-tracking branch 'origin/dev' into wip/cmake
Take 5.

Change-Id: Ifb2d20e95ba824e45e667fba6c2ba45389991cc3
2019-06-03 15:14:42 +02:00
Edward Welbourne
84e89c1e9e Convert uses of QTime as a timer to QElapsedTimer
Change-Id: I2297f61efa5adf9ea5194c7f3ff68574cbcf452c
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
2019-06-14 10:42:33 +02:00
Marc Mutz
b4a88aa758 examples: port away from Java-style iterators
There's no reason to use them here, the Mutable is misleading in a
few instances, ranged-for is much simpler, and more future-proof.

Change-Id: Ifd5eaae95bbaa0b4cf0f435e6cfee6d778817b44
Reviewed-by: David Faure <david.faure@kdab.com>
2019-05-23 17:30:51 +02:00
Tobias Hunger
6630937e63 Merge commit 'dev' into 'wip/cmake-merge'
Change-Id: I176c40d031be26a1dd1cf08843e448a660598783
2019-04-16 16:32:08 +02:00
Tobias Hunger
64c6c943c7 CMake: Add more examples
Change-Id: I7a8a3fd0a844a518592957fe07c6e707dd452d5f
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-03-26 13:03:01 +00:00
Joerg Bornemann
8fe3680193 Add cmdline feature to qmake
[ChangeLog][qmake] A new feature "cmdline" was added that implies
"CONFIG += console" and "CONFIG -= app_bundle".

Task-number: QTBUG-27079
Change-Id: I6e52b07c9341c904bb1424fc717057432f9360e1
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
2019-02-18 07:12:14 +00:00
Paul Wicking
8bd73ad989 Doc: Add missing full stops in briefs
Task-number: QTBUG-68933
Change-Id: I3f2a9f8c562f9a44bb32bddd31d75abbfe6de04d
Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
2018-06-21 14:23:30 +00:00
Rainer Keller
f13b0b2cf2 qtlite: Skip building examples when configured with no-feature-itemviews
Compiling the default examples should be possible without compile errors.

Task-number: QTBUG-53141
Change-Id: I73d8787241291ae6230861a89b38e91d900fede0
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2018-01-12 07:58:20 +00:00
Michael Winkelmann
ab9f4d5db6 Revamp QtConcurrent examples to C++11
I updated signals and slots and for each loops to the new syntax and
replaced most free functions with std::function.

Task-number: QTBUG-60641
Change-Id: I7693f81f71c7f53fcbe83189a0de2fb76ddf99a8
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2017-11-07 09:42:34 +00:00
Friedemann Kleint
dc81a99dec Examples: Remove remains of wince
Task-number: QTBUG-52590
Task-number: QTBUG-60628
Task-number: QTBUG-60633
Task-number: QTBUG-60635
Task-number: QTBUG-60641
Task-number: QTBUG-60659
Change-Id: I9ffc3e25893d2281b19cc12b70e1a92fb2a8b708
Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
2017-07-14 17:30:51 +00:00
Oswald Buddenhagen
fe2f8146d4 prune vestiges of DEPLOYMENT_PLUGIN
the code was broken since 5.0, as it still hardcoded the version number
4 for the plugin basenames.
wince is not supported any more, so there is no point in trying to
restore the code to function.

at a later point, we'll make QTPLUGIN universal enough to cover both
static and dynamic deployment.

Change-Id: I0911ce4aff7a799dd471d6218e046f13dca6d49e
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
2016-12-23 13:25:41 +00:00