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...

#include <QtConcurrent>

This namespace was introduced in QtConcurrent 4.4.

Types

enum ReduceOption { UnorderedReduce, OrderedReduce, SequentialReduce }
flags ReduceOptions

Functions

void blockingFilter(Sequence & sequence, FilterFunction filterFunction)
Sequence blockingFiltered(const Sequence & sequence, FilterFunction filterFunction)
Sequence blockingFiltered(ConstIterator begin, ConstIterator end, FilterFunction filterFunction)
T blockingFilteredReduced(const Sequence & sequence, FilterFunction filterFunction, ReduceFunction reduceFunction, QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce)
T blockingFilteredReduced(ConstIterator begin, ConstIterator end, FilterFunction filterFunction, ReduceFunction reduceFunction, QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce)
void blockingMap(Sequence & sequence, MapFunction function)
void blockingMap(Iterator begin, Iterator end, MapFunction function)
T blockingMapped(const Sequence & sequence, MapFunction function)
T blockingMapped(ConstIterator begin, ConstIterator end, MapFunction function)
T blockingMappedReduced(const Sequence & sequence, MapFunction function, ReduceFunction function, QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce)
T blockingMappedReduced(ConstIterator begin, ConstIterator end, MapFunction function, ReduceFunction function, QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce)
QFuture<void> filter(Sequence & sequence, FilterFunction filterFunction)
QFuture<T> filtered(const Sequence & sequence, FilterFunction filterFunction)
QFuture<T> filtered(ConstIterator begin, ConstIterator end, FilterFunction filterFunction)
QFuture<T> filteredReduced(const Sequence & sequence, FilterFunction filterFunction, ReduceFunction reduceFunction, QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce)
QFuture<T> filteredReduced(ConstIterator begin, ConstIterator end, FilterFunction filterFunction, ReduceFunction reduceFunction, QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce)
QFuture<void> map(Sequence & sequence, MapFunction function)
QFuture<void> map(Iterator begin, Iterator end, MapFunction function)
QFuture<T> mapped(const Sequence & sequence, MapFunction function)
QFuture<T> mapped(ConstIterator begin, ConstIterator end, MapFunction function)
QFuture<T> mappedReduced(const Sequence & sequence, MapFunction function, ReduceFunction function, QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce)
QFuture<T> mappedReduced(ConstIterator begin, ConstIterator end, MapFunction function, ReduceFunction function, QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce)
QFuture<T> run(Function function, ...)

Detailed Description

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

See the Qt Concurrent chapter in the threading documentation.

Type Documentation

enum QtConcurrent::ReduceOption
flags QtConcurrent::ReduceOptions

This enum specifies the order of which results from the map or filter function are passed to the reduce function.

ConstantValueDescription
QtConcurrent::UnorderedReduce0x1Reduction is done in an arbitrary order.
QtConcurrent::OrderedReduce0x2Reduction is done in the order of the original sequence.
QtConcurrent::SequentialReduce0x4Reduction is done sequentially: only one thread will enter the reduce function at a time. (Parallel reduction might be supported in a future version of Qt Concurrent.)

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

Function Documentation

void QtConcurrent::blockingFilter(Sequence & sequence, FilterFunction filterFunction)

Calls filterFunction once for each item in sequence. If filterFunction returns true, the item is kept in sequence; otherwise, the item is removed from sequence.

Note: This function will block until all items in the sequence have been processed.

Sequence QtConcurrent::blockingFiltered(const Sequence & sequence, FilterFunction filterFunction)

Calls filterFunction once for each item in sequence and returns a new Sequence of kept items. If filterFunction returns true, a copy of the item is put in the new Sequence. Otherwise, the item will not appear in the new Sequence.

Note: This function will block until all items in the sequence have been processed.

See also filtered().

Sequence QtConcurrent::blockingFiltered(ConstIterator begin, ConstIterator end, FilterFunction filterFunction)

Calls filterFunction once for each item from begin to end and returns a new Sequence of kept items. If filterFunction returns true, a copy of the item is put in the new Sequence. Otherwise, the item will not appear in the new Sequence.

Note: This function will block until the iterator reaches the end of the sequence being processed.

See also filtered().

T QtConcurrent::blockingFilteredReduced(const Sequence & sequence, FilterFunction filterFunction, ReduceFunction reduceFunction, QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce)

Calls filterFunction once for each item in sequence. If filterFunction returns true for an item, that item is then passed to reduceFunction. In other words, the return value is the result of reduceFunction for each item where filterFunction returns true.

Note that while filterFunction is called concurrently, only one thread at a time will call reduceFunction. The order in which reduceFunction is called is undefined if reduceOptions is QtConcurrent::UnorderedReduce. If reduceOptions is QtConcurrent::OrderedReduce, reduceFunction is called in the order of the original sequence.

Note: This function will block until all items in the sequence have been processed.

See also filteredReduced().

T QtConcurrent::blockingFilteredReduced(ConstIterator begin, ConstIterator end, FilterFunction filterFunction, ReduceFunction reduceFunction, QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce)

Calls filterFunction once for each item from begin to end. If filterFunction returns true for an item, that item is then passed to reduceFunction. In other words, the return value is the result of reduceFunction for each item where filterFunction returns true.

Note that while filterFunction is called concurrently, only one thread at a time will call reduceFunction. The order in which reduceFunction is called is undefined if reduceOptions is QtConcurrent::UnorderedReduce. If reduceOptions is QtConcurrent::OrderedReduce, the reduceFunction is called in the order of the original sequence.

Note: This function will block until the iterator reaches the end of the sequence being processed.

See also filteredReduced().

void QtConcurrent::blockingMap(Sequence & sequence, MapFunction function)

void QtConcurrent::blockingMap(Iterator begin, Iterator end, MapFunction function)

T QtConcurrent::blockingMapped(const Sequence & sequence, MapFunction function)

T QtConcurrent::blockingMapped(ConstIterator begin, ConstIterator end, MapFunction function)

T QtConcurrent::blockingMappedReduced(const Sequence & sequence, MapFunction function, ReduceFunction function, QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce)

T QtConcurrent::blockingMappedReduced(ConstIterator begin, ConstIterator end, MapFunction function, ReduceFunction function, QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce)

QFuture<void> QtConcurrent::filter(Sequence & sequence, FilterFunction filterFunction)

Calls filterFunction once for each item in sequence. If filterFunction returns true, the item is kept in sequence; otherwise, the item is removed from sequence.

QFuture<T> QtConcurrent::filtered(const Sequence & sequence, FilterFunction filterFunction)

Calls filterFunction once for each item in sequence and returns a new Sequence of kept items. If filterFunction returns true, a copy of the item is put in the new Sequence. Otherwise, the item will not appear in the new Sequence.

QFuture<T> QtConcurrent::filtered(ConstIterator begin, ConstIterator end, FilterFunction filterFunction)

Calls filterFunction once for each item from begin to end and returns a new Sequence of kept items. If filterFunction returns true, a copy of the item is put in the new Sequence. Otherwise, the item will not appear in the new Sequence.

QFuture<T> QtConcurrent::filteredReduced(const Sequence & sequence, FilterFunction filterFunction, ReduceFunction reduceFunction, QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce)

Calls filterFunction once for each item in sequence. If filterFunction returns true for an item, that item is then passed to reduceFunction. In other words, the return value is the result of reduceFunction for each item where filterFunction returns true.

Note that while filterFunction is called concurrently, only one thread at a time will call reduceFunction. The order in which reduceFunction is called is undefined if reduceOptions is QtConcurrent::UnorderedReduce. If reduceOptions is QtConcurrent::OrderedReduce, reduceFunction is called in the order of the original sequence.

QFuture<T> QtConcurrent::filteredReduced(ConstIterator begin, ConstIterator end, FilterFunction filterFunction, ReduceFunction reduceFunction, QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce)

Calls filterFunction once for each item from begin to end. If filterFunction returns true for an item, that item is then passed to reduceFunction. In other words, the return value is the result of reduceFunction for each item where filterFunction returns true.

Note that while filterFunction is called concurrently, only one thread at a time will call reduceFunction. The order in which reduceFunction is called is undefined if reduceOptions is QtConcurrent::UnorderedReduce. If reduceOptions is QtConcurrent::OrderedReduce, the reduceFunction is called in the order of the original sequence.

QFuture<void> QtConcurrent::map(Sequence & sequence, MapFunction function)

QFuture<void> QtConcurrent::map(Iterator begin, Iterator end, MapFunction function)

QFuture<T> QtConcurrent::mapped(const Sequence & sequence, MapFunction function)

QFuture<T> QtConcurrent::mapped(ConstIterator begin, ConstIterator end, MapFunction function)

QFuture<T> QtConcurrent::mappedReduced(const Sequence & sequence, MapFunction function, ReduceFunction function, QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce)

QFuture<T> QtConcurrent::mappedReduced(ConstIterator begin, ConstIterator end, MapFunction function, ReduceFunction function, QtConcurrent::ReduceOptions options = UnorderedReduce | SequentialReduce)

QFuture<T> QtConcurrent::run(Function function, ...)