6.0.0-rc4Source

QtConcurrent Namespace

The QtConcurrent namespace provides high-level APIs that make it possible to write multi-threaded programs without using low-level threading primitives. More…

Header#include <QtConcurrent>
CMaketarget_link_libraries(app PRIVATE Nt::Concurrent)
ModuleNt Concurrent C++ Classes

Public Types

Public Functions

QFuture<void>filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
QFuture<void>filter(Sequence &sequence, KeepFunctor &&filterFunction)
voidblockingFilter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
voidblockingFilter(Sequence &sequence, KeepFunctor &&filterFunction)
QFuture<QtPrivate::ItemOf<QtPrivate::ConstIteratorOf<Sequence>>>filtered(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&filterFunction)
QFuture<QtPrivate::ItemOf<Iterator>>filtered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&filterFunction)
QFuture<QtPrivate::ItemOf<QtPrivate::ConstIteratorOf<Sequence>>>filtered(Sequence &&sequence, KeepFunctor &&filterFunction)
QFuture<QtPrivate::ItemOf<Iterator>>filtered(Iterator begin, Iterator end, KeepFunctor &&filterFunction)
std::decay_t<Sequence>blockingFiltered(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&filterFunction)
OutputSequenceblockingFiltered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&filterFunction)
std::decay_t<Sequence>blockingFiltered(Sequence &&sequence, KeepFunctor &&filterFunction)
OutputSequenceblockingFiltered(Iterator begin, Iterator end, KeepFunctor &&filterFunction)
QFuture<ResultType>filteredReduced(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
QFuture<ResultType>filteredReduced(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
QFuture<ResultType>filteredReduced(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
QFuture<ResultType>filteredReduced(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
QFuture<ResultType>filteredReduced(Sequence &&sequence, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
QFuture<ResultType>filteredReduced(Sequence &&sequence, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
QFuture<ResultType>filteredReduced(Iterator begin, Iterator end, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
QFuture<ResultType>filteredReduced(Iterator begin, Iterator end, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
ResultTypeblockingFilteredReduced(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
ResultTypeblockingFilteredReduced(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
ResultTypeblockingFilteredReduced(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
ResultTypeblockingFilteredReduced(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
ResultTypeblockingFilteredReduced(Sequence &&sequence, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
ResultTypeblockingFilteredReduced(Sequence &&sequence, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
ResultTypeblockingFilteredReduced(Iterator begin, Iterator end, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
ResultTypeblockingFilteredReduced(Iterator begin, Iterator end, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
QFuture<void>map(QThreadPool *pool, Sequence &&sequence, MapFunctor &&function)
QFuture<void>map(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function)
QFuture<void>map(Sequence &&sequence, MapFunctor &&function)
QFuture<void>map(Iterator begin, Iterator end, MapFunctor &&function)
voidblockingMap(QThreadPool *pool, Sequence &&sequence, MapFunctor &&function)
voidblockingMap(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function)
voidblockingMap(Sequence &&sequence, MapFunctor &&function)
voidblockingMap(Iterator begin, Iterator end, MapFunctor &&function)
QFuture<QtPrivate::MapResult<MapFunctor, QtPrivate::ConstIteratorOf<Sequence>>>mapped(QThreadPool *pool, Sequence &&sequence, MapFunctor &&function)
QFuture<QtPrivate::MapResult<MapFunctor, Iterator>>mapped(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function)
QFuture<QtPrivate::MapResult<MapFunctor, QtPrivate::ConstIteratorOf<Sequence>>>mapped(Sequence &&sequence, MapFunctor &&function)
QFuture<QtPrivate::MapResult<MapFunctor, Iterator>>mapped(Iterator begin, Iterator end, MapFunctor &&function)
OutputSequenceblockingMapped(QThreadPool *pool, Sequence &&sequence, MapFunctor &&function)
OutputSequenceblockingMapped(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function)
OutputSequenceblockingMapped(Sequence &&sequence, MapFunctor &&function)
OutputSequenceblockingMapped(Iterator begin, Iterator end, MapFunctor &&function)
QFuture<ResultType>mappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&function, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
QFuture<ResultType>mappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&function, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
QFuture<ResultType>mappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
QFuture<ResultType>mappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
QFuture<ResultType>mappedReduced(Sequence &&sequence, MapFunctor &&function, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
QFuture<ResultType>mappedReduced(Sequence &&sequence, MapFunctor &&function, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
QFuture<ResultType>mappedReduced(Iterator begin, Iterator end, MapFunctor &&function, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
QFuture<ResultType>mappedReduced(Iterator begin, Iterator end, MapFunctor &&function, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
ResultTypeblockingMappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&function, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
ResultTypeblockingMappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&function, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
ResultTypeblockingMappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
ResultTypeblockingMappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
ResultTypeblockingMappedReduced(Sequence &&sequence, MapFunctor &&function, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
ResultTypeblockingMappedReduced(Sequence &&sequence, MapFunctor &&function, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
ResultTypeblockingMappedReduced(Iterator begin, Iterator end, MapFunctor &&function, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
ResultTypeblockingMappedReduced(Iterator begin, Iterator end, MapFunctor &&function, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))
autorun(QThreadPool *pool, Function &&function, Args &&...args)
autorun(Function &&function, Args &&...args)
[[nodiscard]] QTaskBuilder<std::decay_t<Task>>task(Task &&task)

Detailed Description

The functions come in three groups:

QList<QImage> images = load();
QFuture<QImage> thumbnails = QtConcurrent::mapped(images, [](const QImage &image) { return image.scaled(64, 64); });
QFutureWatcher<QImage> watcher;
QObject::connect(&watcher, &QFutureWatcherBase::resultReadyAt, [&](int i) { show(i, watcher.resultAt(i)); });
watcher.setFuture(thumbnails);

Every map and filter function takes a sequence or a pair of iterators, optionally a QThreadPool in front (the global pool otherwise), and has a blocking form that returns the result instead of a future. The future of a map or a filter reports the number of items handled as its progress, can be canceled and suspended, and throws the first exception that one of the functions threw. The functions must be safe to call from several threads at a time, except the reduce function, which one thread calls at a time.

See also QFuture, QFutureWatcher, QThreadPool and QPromise.

Differences from Qt

The items are handed out in blocks of a fixed size, chosen from the number of items and of threads, not in blocks that adapt to the speed of the function. A suspended computation is reported as suspended when the first of its threads stops, while the others may still finish the block they are in. The blocking functions run in the calling thread too, so they work from a thread of a pool that has no thread to spare; waiting for the future of a non-blocking function from such a thread does not, since QFuture::waitForFinished() does not lend the thread to the pool. A sequence has at most INT_MAX items. There are no QtConcurrent::median or ThreadEngine classes, and blockingMapped() deduces its container for class templates with the item type as their first argument only.

Member Type Documentation

enum QtConcurrent::FutureResult

This enum says what QTaskBuilder::spawn() does with the future of the task.

ConstantDescription
QtConcurrent::IgnoreThe future is dropped. The task runs all the same.

enum QtConcurrent::ReduceOption

This enum describes the order in which the reduce function of mappedReduced() and filteredReduced() gets the intermediate results. The reduce function is never called by two threads at a time, whatever the option.

ConstantDescription
QtConcurrent::UnorderedReduceThe results are reduced in the order in which the threads produce them.
QtConcurrent::OrderedReduceThe results are reduced in the order of the items in the sequence.
QtConcurrent::SequentialReduceOne thread at a time enters the reduce function. This is always the case, so the value only exists to be combined with one of the other two.

typedef QtConcurrent::ReduceOptions

The ReduceOptions type is a typedef for QFlags<ReduceOption>. It stores an OR combination of ReduceOption values.

Function Documentation

template <typename Sequence, typename KeepFunctor, QtPrivate::IfSequence<Sequence> = true>void QtConcurrent::blockingFilter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)

Calls filterFunction once for each item of sequence, in the threads of pool and in the calling thread, and removes the items for which it returns false before it returns. An exception that filterFunction throws is thrown again here, and sequence is then unchanged.

This function was introduced in 6.0.

See also filter() and blockingFiltered().

template <typename Sequence, typename KeepFunctor, QtPrivate::IfSequence<Sequence> = true>void QtConcurrent::blockingFilter(Sequence &sequence, KeepFunctor &&filterFunction)

This is an overloaded function.

Filters sequence in place with filterFunction, in the threads of the global QThreadPool and in the calling thread, and waits for it.

template <typename Sequence, typename KeepFunctor, QtPrivate::IfSequence<Sequence> = true>std::decay_t<Sequence> QtConcurrent::blockingFiltered(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&filterFunction)

Calls filterFunction once for each item of sequence, in the threads of pool and in the calling thread, and returns a sequence of the same type with the items for which it returns true, in their order. An exception that filterFunction throws is thrown again here.

This function was introduced in 6.0.

See also filtered() and blockingFilter().

template <typename OutputSequence, typename Iterator, typename KeepFunctor, QtPrivate::IfIterator<Iterator> = true>OutputSequence QtConcurrent::blockingFiltered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&filterFunction)

This is an overloaded function.

Filters the items from begin to end with filterFunction, in the threads of pool and in the calling thread, and returns the items that are kept in an OutputSequence, which has to be named.

template <typename Sequence, typename KeepFunctor, QtPrivate::IfSequence<Sequence> = true>std::decay_t<Sequence> QtConcurrent::blockingFiltered(Sequence &&sequence, KeepFunctor &&filterFunction)

This is an overloaded function.

Filters sequence with filterFunction, in the threads of the global QThreadPool and in the calling thread, and returns the items that are kept.

template <typename OutputSequence, typename Iterator, typename KeepFunctor, QtPrivate::IfIterator<Iterator> = true>OutputSequence QtConcurrent::blockingFiltered(Iterator begin, Iterator end, KeepFunctor &&filterFunction)

This is an overloaded function.

Filters the items from begin to end with filterFunction, in the threads of the global QThreadPool and in the calling thread, and returns the items that are kept in an OutputSequence, which has to be named.

template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, QtPrivate::IfSequence<Sequence> = true>ResultType QtConcurrent::blockingFilteredReduced(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

Calls filterFunction once for each item of sequence, in the threads of pool and in the calling thread, combines the items for which it returns true into one value of type ResultType with reduceFunction, and returns that value. options says in which order the items are reduced. An exception that one of the functions throws is thrown again here.

This function was introduced in 6.0.

See also filteredReduced() and blockingFiltered().

template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, QtPrivate::IfSequence<Sequence> = true, QtPrivate::IfInitialValue<InitialValueType, ResultType> = true>ResultType QtConcurrent::blockingFilteredReduced(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Filters the items of sequence with filterFunction, in the threads of pool and in the calling thread, and reduces the items that are kept with reduceFunction as options says, starting from initialValue. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, QtPrivate::IfIterator<Iterator> = true>ResultType QtConcurrent::blockingFilteredReduced(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Filters the items from begin to end with filterFunction, in the threads of pool and in the calling thread, and reduces the items that are kept with reduceFunction as options says. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, QtPrivate::IfIterator<Iterator> = true, QtPrivate::IfInitialValue<InitialValueType, ResultType> = true>ResultType QtConcurrent::blockingFilteredReduced(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Filters the items from begin to end with filterFunction, in the threads of pool and in the calling thread, and reduces the items that are kept with reduceFunction as options says, starting from initialValue. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, QtPrivate::IfSequence<Sequence> = true>ResultType QtConcurrent::blockingFilteredReduced(Sequence &&sequence, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Filters the items of sequence with filterFunction, in the threads of the global QThreadPool and in the calling thread, and reduces the items that are kept with reduceFunction as options says. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, QtPrivate::IfSequence<Sequence> = true, QtPrivate::IfInitialValue<InitialValueType, ResultType> = true>ResultType QtConcurrent::blockingFilteredReduced(Sequence &&sequence, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Filters the items of sequence with filterFunction, in the threads of the global QThreadPool and in the calling thread, and reduces the items that are kept with reduceFunction as options says, starting from initialValue. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, QtPrivate::IfIterator<Iterator> = true>ResultType QtConcurrent::blockingFilteredReduced(Iterator begin, Iterator end, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Filters the items from begin to end with filterFunction, in the threads of the global QThreadPool and in the calling thread, and reduces the items that are kept with reduceFunction as options says. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, QtPrivate::IfIterator<Iterator> = true, QtPrivate::IfInitialValue<InitialValueType, ResultType> = true>ResultType QtConcurrent::blockingFilteredReduced(Iterator begin, Iterator end, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Filters the items from begin to end with filterFunction, in the threads of the global QThreadPool and in the calling thread, and reduces the items that are kept with reduceFunction as options says, starting from initialValue. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename Sequence, typename MapFunctor, QtPrivate::IfSequence<Sequence> = true>void QtConcurrent::blockingMap(QThreadPool *pool, Sequence &&sequence, MapFunctor &&function)

Calls function once for each item of sequence, in the threads of pool and in the calling thread, and returns when all items have been handled. The items are changed in place. An exception that function throws is thrown again here.

This function was introduced in 6.0.

See also map() and blockingMapped().

template <typename Iterator, typename MapFunctor, QtPrivate::IfIterator<Iterator> = true>void QtConcurrent::blockingMap(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function)

This is an overloaded function.

Calls function for each item from begin to end, in place, in the threads of pool and in the calling thread, and waits for it.

template <typename Sequence, typename MapFunctor, QtPrivate::IfSequence<Sequence> = true>void QtConcurrent::blockingMap(Sequence &&sequence, MapFunctor &&function)

This is an overloaded function.

Calls function for each item of sequence, in place, in the threads of the global QThreadPool and in the calling thread, and waits for it.

template <typename Iterator, typename MapFunctor, QtPrivate::IfIterator<Iterator> = true>void QtConcurrent::blockingMap(Iterator begin, Iterator end, MapFunctor &&function)

This is an overloaded function.

Calls function for each item from begin to end, in place, in the threads of the global QThreadPool and in the calling thread, and waits for it.

template <typename OutputSequence, typename Sequence, typename MapFunctor, QtPrivate::IfSequence<Sequence> = true>OutputSequence QtConcurrent::blockingMapped(QThreadPool *pool, Sequence &&sequence, MapFunctor &&function)

Calls function once for each item of sequence, in the threads of pool and in the calling thread, and returns the results, in the order of the items, in a container of type OutputSequence. The container needs push_back() or a one-argument insert(). An exception that function throws is thrown again here.

std::vector<int> lengths = QtConcurrent::blockingMapped<std::vector<int>>(&pool, words, &QString::size);

Without the OutputSequence template argument, the result is a container like sequence that holds the mapped type: a QList<int> gives a QList<QString>, for example.

This function was introduced in 6.0.

See also mapped() and blockingMap().

template <typename OutputSequence, typename Iterator, typename MapFunctor, QtPrivate::IfIterator<Iterator> = true>OutputSequence QtConcurrent::blockingMapped(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function)

This is an overloaded function.

Calls function for each item from begin to end, in the threads of pool and in the calling thread, and returns the results in an OutputSequence. Without the OutputSequence template argument, the result is a QList.

template <typename OutputSequence, typename Sequence, typename MapFunctor, QtPrivate::IfSequence<Sequence> = true>OutputSequence QtConcurrent::blockingMapped(Sequence &&sequence, MapFunctor &&function)

This is an overloaded function.

Calls function for each item of sequence, in the threads of the global QThreadPool and in the calling thread, and returns the results in an OutputSequence. Without the OutputSequence template argument, the result is a container like sequence that holds the mapped type, or a QList if sequence is not a template with the item type as its first argument.

template <typename OutputSequence, typename Iterator, typename MapFunctor, QtPrivate::IfIterator<Iterator> = true>OutputSequence QtConcurrent::blockingMapped(Iterator begin, Iterator end, MapFunctor &&function)

This is an overloaded function.

Calls function for each item from begin to end, in the threads of the global QThreadPool and in the calling thread, and returns the results in an OutputSequence. Without the OutputSequence template argument, the result is a QList.

template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, QtPrivate::IfSequence<Sequence> = true>ResultType QtConcurrent::blockingMappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&function, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

Calls function once for each item of sequence, in the threads of pool and in the calling thread, combines what the calls return into one value of type ResultType with reduceFunction, and returns that value. options says in which order the results are reduced. An exception that one of the functions throws is thrown again here.

This function was introduced in 6.0.

See also mappedReduced() and blockingMapped().

template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType, QtPrivate::IfSequence<Sequence> = true, QtPrivate::IfInitialValue<InitialValueType, ResultType> = true>ResultType QtConcurrent::blockingMappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&function, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Maps the items of sequence with function, in the threads of pool and in the calling thread, and reduces the results with reduceFunction as options says, starting from initialValue. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, QtPrivate::IfIterator<Iterator> = true>ResultType QtConcurrent::blockingMappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Maps the items from begin to end with function, in the threads of pool and in the calling thread, and reduces the results with reduceFunction as options says. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, typename InitialValueType, QtPrivate::IfIterator<Iterator> = true, QtPrivate::IfInitialValue<InitialValueType, ResultType> = true>ResultType QtConcurrent::blockingMappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Maps the items from begin to end with function, in the threads of pool and in the calling thread, and reduces the results with reduceFunction as options says, starting from initialValue. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, QtPrivate::IfSequence<Sequence> = true>ResultType QtConcurrent::blockingMappedReduced(Sequence &&sequence, MapFunctor &&function, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Maps the items of sequence with function, in the threads of the global QThreadPool and in the calling thread, and reduces the results with reduceFunction as options says. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType, QtPrivate::IfSequence<Sequence> = true, QtPrivate::IfInitialValue<InitialValueType, ResultType> = true>ResultType QtConcurrent::blockingMappedReduced(Sequence &&sequence, MapFunctor &&function, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Maps the items of sequence with function, in the threads of the global QThreadPool and in the calling thread, and reduces the results with reduceFunction as options says, starting from initialValue. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, QtPrivate::IfIterator<Iterator> = true>ResultType QtConcurrent::blockingMappedReduced(Iterator begin, Iterator end, MapFunctor &&function, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Maps the items from begin to end with function, in the threads of the global QThreadPool and in the calling thread, and reduces the results with reduceFunction as options says. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, typename InitialValueType, QtPrivate::IfIterator<Iterator> = true, QtPrivate::IfInitialValue<InitialValueType, ResultType> = true>ResultType QtConcurrent::blockingMappedReduced(Iterator begin, Iterator end, MapFunctor &&function, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Maps the items from begin to end with function, in the threads of the global QThreadPool and in the calling thread, and reduces the results with reduceFunction as options says, starting from initialValue. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename Sequence, typename KeepFunctor, QtPrivate::IfSequence<Sequence> = true>QFuture<void> QtConcurrent::filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)

Calls filterFunction once for each item of sequence, in the threads of pool, and removes the items for which it returns false. Returns a future for the end of it. filterFunction takes a const reference to an item and may be a const member function of the item type.

QStringList words = load();
QFuture<void> done = QtConcurrent::filter(&pool, words, [](const QString &word) { return !word.isEmpty(); });

sequence is not copied: it has to stay alive, and untouched by other threads, until the future finishes. It is assigned once, at the end, with the items that are kept in their order; a computation that is canceled or that throws leaves it as it was. The sequence type needs a default constructor and push_back() or a one-argument insert().

This function was introduced in 6.0.

See also blockingFilter(), filtered() and filteredReduced().

template <typename Sequence, typename KeepFunctor, QtPrivate::IfSequence<Sequence> = true>QFuture<void> QtConcurrent::filter(Sequence &sequence, KeepFunctor &&filterFunction)

This is an overloaded function.

Filters sequence in place with filterFunction, in the threads of the global QThreadPool.

template <typename Sequence, typename KeepFunctor, QtPrivate::IfSequence<Sequence> = true>QFuture<QtPrivate::ItemOf<QtPrivate::ConstIteratorOf<Sequence>>> QtConcurrent::filtered(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&filterFunction)

Calls filterFunction once for each item of sequence, in the threads of pool, and returns a future with copies of the items for which it returns true, in their order. filterFunction takes a const reference to an item and may be a const member function of the item type.

QFuture<QString> longWords = QtConcurrent::filtered(&pool, words, [](const QString &word) { return word.size() > 7; });

sequence is copied, or moved if it is an rvalue, into the computation. The results become available in order while the computation runs.

This function was introduced in 6.0.

See also blockingFiltered(), filter() and filteredReduced().

template <typename Iterator, typename KeepFunctor, QtPrivate::IfIterator<Iterator> = true>QFuture<QtPrivate::ItemOf<Iterator>> QtConcurrent::filtered(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&filterFunction)

This is an overloaded function.

Filters the items from begin to end with filterFunction, in the threads of pool, and returns a future with the items that are kept. The range has to stay valid until the future finishes.

template <typename Sequence, typename KeepFunctor, QtPrivate::IfSequence<Sequence> = true>QFuture<QtPrivate::ItemOf<QtPrivate::ConstIteratorOf<Sequence>>> QtConcurrent::filtered(Sequence &&sequence, KeepFunctor &&filterFunction)

This is an overloaded function.

Filters the items of sequence with filterFunction, in the threads of the global QThreadPool, and returns a future with the items that are kept.

template <typename Iterator, typename KeepFunctor, QtPrivate::IfIterator<Iterator> = true>QFuture<QtPrivate::ItemOf<Iterator>> QtConcurrent::filtered(Iterator begin, Iterator end, KeepFunctor &&filterFunction)

This is an overloaded function.

Filters the items from begin to end with filterFunction, in the threads of the global QThreadPool, and returns a future with the items that are kept. The range has to stay valid until the future finishes.

template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, QtPrivate::IfSequence<Sequence> = true>QFuture<ResultType> QtConcurrent::filteredReduced(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

Calls filterFunction once for each item of sequence, in the threads of pool, and combines the items for which it returns true into one value with reduceFunction. Returns a future for that value, whose type is ResultType. reduceFunction is called as reduceFunction(result, item), by one thread at a time, and options says whether the items are reduced in their order or as they come. The value starts out value-initialized, or as initialValue in the overloads that take one.

QFuture<int> sumOfEven = QtConcurrent::filteredReduced<int>(&pool, numbers, [](int n) { return n % 2 == 0; }, [](int &sum, int n) { sum += n; });

The overloads without a ResultType template argument take it from the first parameter of reduceFunction, or from its class if it is a member function. sequence is copied, or moved, into the computation.

This function was introduced in 6.0.

See also blockingFilteredReduced(), filtered(), mappedReduced() and ReduceOption.

template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, QtPrivate::IfSequence<Sequence> = true, QtPrivate::IfInitialValue<InitialValueType, ResultType> = true>QFuture<ResultType> QtConcurrent::filteredReduced(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Filters the items of sequence with filterFunction, in the threads of pool, and reduces the items that are kept with reduceFunction as options says, starting from initialValue. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, QtPrivate::IfIterator<Iterator> = true>QFuture<ResultType> QtConcurrent::filteredReduced(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Filters the items from begin to end with filterFunction, in the threads of pool, and reduces the items that are kept with reduceFunction as options says. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, QtPrivate::IfIterator<Iterator> = true, QtPrivate::IfInitialValue<InitialValueType, ResultType> = true>QFuture<ResultType> QtConcurrent::filteredReduced(QThreadPool *pool, Iterator begin, Iterator end, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Filters the items from begin to end with filterFunction, in the threads of pool, and reduces the items that are kept with reduceFunction as options says, starting from initialValue. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, QtPrivate::IfSequence<Sequence> = true>QFuture<ResultType> QtConcurrent::filteredReduced(Sequence &&sequence, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Filters the items of sequence with filterFunction, in the threads of the global QThreadPool, and reduces the items that are kept with reduceFunction as options says. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, QtPrivate::IfSequence<Sequence> = true, QtPrivate::IfInitialValue<InitialValueType, ResultType> = true>QFuture<ResultType> QtConcurrent::filteredReduced(Sequence &&sequence, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Filters the items of sequence with filterFunction, in the threads of the global QThreadPool, and reduces the items that are kept with reduceFunction as options says, starting from initialValue. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, QtPrivate::IfIterator<Iterator> = true>QFuture<ResultType> QtConcurrent::filteredReduced(Iterator begin, Iterator end, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Filters the items from begin to end with filterFunction, in the threads of the global QThreadPool, and reduces the items that are kept with reduceFunction as options says. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor, typename InitialValueType, QtPrivate::IfIterator<Iterator> = true, QtPrivate::IfInitialValue<InitialValueType, ResultType> = true>QFuture<ResultType> QtConcurrent::filteredReduced(Iterator begin, Iterator end, KeepFunctor &&filterFunction, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Filters the items from begin to end with filterFunction, in the threads of the global QThreadPool, and reduces the items that are kept with reduceFunction as options says, starting from initialValue. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename Sequence, typename MapFunctor, QtPrivate::IfSequence<Sequence> = true>QFuture<void> QtConcurrent::map(QThreadPool *pool, Sequence &&sequence, MapFunctor &&function)

Calls function once for each item of sequence, in the threads of pool, and returns a future for the end of it. The items are changed in place: function takes a reference to an item, and what it returns is ignored. It may be a member function of the item type.

QList<QImage> images = load();
QFuture<void> done = QtConcurrent::map(&pool, images, [](QImage &image) { image.invertPixels(); });

sequence is not copied, so it has to stay alive, and untouched by other threads, until the future finishes. The future reports the number of items handled as its progress, and can be canceled and suspended.

This function was introduced in 6.0.

See also blockingMap(), mapped() and mappedReduced().

template <typename Iterator, typename MapFunctor, QtPrivate::IfIterator<Iterator> = true>QFuture<void> QtConcurrent::map(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function)

This is an overloaded function.

Calls function for each item from begin to end, in place, in the threads of pool.

template <typename Sequence, typename MapFunctor, QtPrivate::IfSequence<Sequence> = true>QFuture<void> QtConcurrent::map(Sequence &&sequence, MapFunctor &&function)

This is an overloaded function.

Calls function for each item of sequence, in place, in the threads of the global QThreadPool.

template <typename Iterator, typename MapFunctor, QtPrivate::IfIterator<Iterator> = true>QFuture<void> QtConcurrent::map(Iterator begin, Iterator end, MapFunctor &&function)

This is an overloaded function.

Calls function for each item from begin to end, in place, in the threads of the global QThreadPool.

template <typename Sequence, typename MapFunctor, QtPrivate::IfSequence<Sequence> = true>QFuture<QtPrivate::MapResult<MapFunctor, QtPrivate::ConstIteratorOf<Sequence>>> QtConcurrent::mapped(QThreadPool *pool, Sequence &&sequence, MapFunctor &&function)

Calls function once for each item of sequence, in the threads of pool, and returns a future with what the calls return, in the order of the items. function takes an item, by value or by const reference, and may be a const member function of the item type. The result type of the future is the decayed return type of function.

QFuture<QImage> thumbnails = QtConcurrent::mapped(&pool, images, [](const QImage &image) { return image.scaled(100, 100); });

sequence is copied, or moved if it is an rvalue, into the computation, so it does not have to outlive the call. Results become available as they are computed: QFuture::resultAt() waits for one of them.

This function was introduced in 6.0.

See also blockingMapped(), map() and mappedReduced().

template <typename Iterator, typename MapFunctor, QtPrivate::IfIterator<Iterator> = true>QFuture<QtPrivate::MapResult<MapFunctor, Iterator>> QtConcurrent::mapped(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function)

This is an overloaded function.

Calls function for each item from begin to end, in the threads of pool, and returns a future with the results in order. The range has to stay valid until the future finishes.

template <typename Sequence, typename MapFunctor, QtPrivate::IfSequence<Sequence> = true>QFuture<QtPrivate::MapResult<MapFunctor, QtPrivate::ConstIteratorOf<Sequence>>> QtConcurrent::mapped(Sequence &&sequence, MapFunctor &&function)

This is an overloaded function.

Calls function for each item of sequence, in the threads of the global QThreadPool, and returns a future with the results in order.

template <typename Iterator, typename MapFunctor, QtPrivate::IfIterator<Iterator> = true>QFuture<QtPrivate::MapResult<MapFunctor, Iterator>> QtConcurrent::mapped(Iterator begin, Iterator end, MapFunctor &&function)

This is an overloaded function.

Calls function for each item from begin to end, in the threads of the global QThreadPool, and returns a future with the results in order. The range has to stay valid until the future finishes.

template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, QtPrivate::IfSequence<Sequence> = true>QFuture<ResultType> QtConcurrent::mappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&function, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

Calls function once for each item of sequence, in the threads of pool, and combines what the calls return into one value with reduceFunction. Returns a future for that value, whose type is ResultType. reduceFunction is called as reduceFunction(result, intermediate) with a reference to the value and one result of function; it is never called by two threads at a time. options says whether the results are reduced in the order of the items or as they come. The value starts out value-initialized, or as initialValue in the overloads that take one.

QFuture<int> total = QtConcurrent::mappedReduced<int>(&pool, words, &QString::size, [](int &sum, qsizetype n) { sum += int(n); });

The overloads without a ResultType template argument take it from the first parameter of reduceFunction, or from its class if it is a member function. That does not work for a generic lambda or an overloaded function object, which need the explicit form. sequence is copied, or moved, into the computation.

This function was introduced in 6.0.

See also blockingMappedReduced(), mapped(), filteredReduced() and ReduceOption.

template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType, QtPrivate::IfSequence<Sequence> = true, QtPrivate::IfInitialValue<InitialValueType, ResultType> = true>QFuture<ResultType> QtConcurrent::mappedReduced(QThreadPool *pool, Sequence &&sequence, MapFunctor &&function, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Maps the items of sequence with function, in the threads of pool, and reduces the results with reduceFunction as options says, starting from initialValue. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, QtPrivate::IfIterator<Iterator> = true>QFuture<ResultType> QtConcurrent::mappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Maps the items from begin to end with function, in the threads of pool, and reduces the results with reduceFunction as options says. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, typename InitialValueType, QtPrivate::IfIterator<Iterator> = true, QtPrivate::IfInitialValue<InitialValueType, ResultType> = true>QFuture<ResultType> QtConcurrent::mappedReduced(QThreadPool *pool, Iterator begin, Iterator end, MapFunctor &&function, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Maps the items from begin to end with function, in the threads of pool, and reduces the results with reduceFunction as options says, starting from initialValue. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, QtPrivate::IfSequence<Sequence> = true>QFuture<ResultType> QtConcurrent::mappedReduced(Sequence &&sequence, MapFunctor &&function, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Maps the items of sequence with function, in the threads of the global QThreadPool, and reduces the results with reduceFunction as options says. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor, typename InitialValueType, QtPrivate::IfSequence<Sequence> = true, QtPrivate::IfInitialValue<InitialValueType, ResultType> = true>QFuture<ResultType> QtConcurrent::mappedReduced(Sequence &&sequence, MapFunctor &&function, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Maps the items of sequence with function, in the threads of the global QThreadPool, and reduces the results with reduceFunction as options says, starting from initialValue. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, QtPrivate::IfIterator<Iterator> = true>QFuture<ResultType> QtConcurrent::mappedReduced(Iterator begin, Iterator end, MapFunctor &&function, ReduceFunctor &&reduceFunction, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Maps the items from begin to end with function, in the threads of the global QThreadPool, and reduces the results with reduceFunction as options says. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor, typename InitialValueType, QtPrivate::IfIterator<Iterator> = true, QtPrivate::IfInitialValue<InitialValueType, ResultType> = true>QFuture<ResultType> QtConcurrent::mappedReduced(Iterator begin, Iterator end, MapFunctor &&function, ReduceFunctor &&reduceFunction, InitialValueType &&initialValue, ReduceOptions options = ReduceOptions(UnorderedReduce | SequentialReduce))

This is an overloaded function.

Maps the items from begin to end with function, in the threads of the global QThreadPool, and reduces the results with reduceFunction as options says, starting from initialValue. Without the ResultType template argument, the result type is taken from reduceFunction.

template <typename Function, typename... Args>auto QtConcurrent::run(QThreadPool *pool, Function &&function, Args &&...args)

Runs function with args in a thread of pool, or queues it there until a thread is free, and returns a future for what it returns. function and args are copied, or moved if they are rvalues, into the task; pass std::ref() or a pointer for what the function should share with the caller. function may be a member function, with the object as the first of args.

QFuture<QString> text = QtConcurrent::run(&pool, [](const QString &path) { return load(path); }, path);

If the first parameter of function is a QPromise<T> &, the function gets a promise in front of args and the result is a QFuture<T>. Such a function can report several results and its progress, and honour cancellation and suspension:

QFuture<int> squares = QtConcurrent::run(&pool, [](QPromise<int> &promise, int n) {
    for (int i = 0; i < n && !promise.isCanceled(); ++i)
        promise.addResult(i * i);
}, 100);

An exception that function throws is stored in the future. A future that is canceled before its task starts does not run function at all.

This function was introduced in 6.0.

See also task() and QThreadPool::start().

template <typename Function, typename... Args>auto QtConcurrent::run(Function &&function, Args &&...args)

This is an overloaded function.

Runs function with args in a thread of the global QThreadPool.

This function was introduced in 6.0.

template <typename Task>[[nodiscard]] QTaskBuilder<std::decay_t<Task>> QtConcurrent::task(Task &&task)

Returns a builder for running task, which is copied, or moved if it is an rvalue, in another thread. Set its arguments, thread pool and priority on the builder and start it with QTaskBuilder::spawn().

This function was introduced in 6.0.

See also run() and QTaskBuilder.