summaryrefslogtreecommitdiffstats
path: root/examples/qtconcurrent/wordcount/doc/src/qtconcurrent-wordcount.qdoc
diff options
context:
space:
mode:
Diffstat (limited to 'examples/qtconcurrent/wordcount/doc/src/qtconcurrent-wordcount.qdoc')
-rw-r--r--examples/qtconcurrent/wordcount/doc/src/qtconcurrent-wordcount.qdoc44
1 files changed, 37 insertions, 7 deletions
diff --git a/examples/qtconcurrent/wordcount/doc/src/qtconcurrent-wordcount.qdoc b/examples/qtconcurrent/wordcount/doc/src/qtconcurrent-wordcount.qdoc
index 2c5724bc85..adefdfdc59 100644
--- a/examples/qtconcurrent/wordcount/doc/src/qtconcurrent-wordcount.qdoc
+++ b/examples/qtconcurrent/wordcount/doc/src/qtconcurrent-wordcount.qdoc
@@ -1,15 +1,45 @@
-// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\example wordcount
- \title QtConcurrent Word Count Example
- \brief Demonstrates how to use the map-reduce algorithm.
+ \meta tags {threads, console}
+ \title Word Count
\ingroup qtconcurrentexamples
+ \examplecategory {Data Processing & I/O}
+ \brief Demonstrates how to use the map-reduce algorithm.
+
+ The Qt Concurrent \e {Word Count} example demonstrates the use of the
+ map-reduce algorithm when applied to the problem of counting words in a
+ collection of files.
+
+ First, the Application starts a QFileDialog to select a starting
+ path, and then prints the output to the console.
+
+ \include examples-run.qdocinc
+
+ \section1 Comparing the operations
+
+ Compare a single-threaded, sequential approach to counting the words in
+ the text files to a multithreaded approach with mappedReduced():
+
+ \dots
+ \snippet wordcount/main.cpp 1
+ \dots
+ \snippet wordcount/main.cpp 2
+ \dots
+
+ The first argument to the \l {QtConcurrent::}{mappedReduced} function is the
+ container to operate on. The second argument is the mapping function
+ \c {countWords()}. It is called in parallel by multiple threads. The
+ third argument is the reducing function \c {reduce()}. It is called
+ once for each result returned by the mapping function, and generates the
+ final computation result.
- The QtConcurrent Word Count example demonstrates the use of the map-reduce
- algorithm when applied to the problem of counting words in a collection
- of files.
+ The function returns a QFuture object of type \c WordCount. Call the
+ \l {QFuture::}{result} function immediately on this QFuture to block further
+ execution until the result becomes available.
- This is a command-line application.
+ \note The mapping function must be thread-safe since it is called from
+ multiple threads.
*/