QtConcurrent 名称空间

The QtConcurrent 名称空间提供高级 API 使之可能不使用低级线程原语,编写多线程程序。 更多...

头: #include <QtConcurrent>
qmake: QT += concurrent
Since: Qt 4.4

类型

enum ReduceOption { UnorderedReduce, OrderedReduce, SequentialReduce }
flags ReduceOptions

函数

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 mapFunction , ReduceFunction reduceFunction , QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce)
T blockingMappedReduced (ConstIterator begin , ConstIterator end , MapFunction mapFunction , ReduceFunction reduceFunction , QtConcurrent::ReduceOptions reduceOptions = 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 mapFunction , ReduceFunction reduceFunction , QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce)
QFuture<T> mappedReduced (ConstIterator begin , ConstIterator end , MapFunction mapFunction , ReduceFunction reduceFunction , QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce)
QFuture<T> run (Function function , ... )
QFuture<T> run (QThreadPool * pool , Function function , ... )

详细描述

The QtConcurrent 名称空间提供高级 API 使之可能不使用低级线程原语,编写多线程程序。

Qt Concurrent 模块文档编制了解可用函数的概述,或见下文了解每个函数的详细信息。

类型文档编制

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.

常量 描述
QtConcurrent::UnorderedReduce 0x1 按任意次序履行缩减。
QtConcurrent::OrderedReduce 0x2 Reduction is done in the order of the original sequence.
QtConcurrent::SequentialReduce 0x4 Reduction 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.

函数文档编制

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

调用 filterFunction once for each item in sequence 。若 filterFunction 返回 true , the item is kept in sequence ; otherwise, the item is removed from sequence .

注意: 此函数将阻塞,直到已处理所有序列项。

另请参阅 并发过滤和过滤缩减 .

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

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

注意: 此函数将阻塞,直到已处理所有序列项。

另请参阅 filtered () 和 并发过滤和过滤缩减 .

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

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

注意: 此函数将阻塞,直到迭代器到达正处理序列的末尾。

另请参阅 filtered () 和 并发过滤和过滤缩减 .

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

调用 filterFunction once for each item in sequence 。若 filterFunction 返回 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 返回 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 。若 reduceOptions is QtConcurrent::OrderedReduce , reduceFunction is called in the order of the original sequence.

注意: 此函数将阻塞,直到已处理所有序列项。

另请参阅 filteredReduced () 和 并发过滤和过滤缩减 .

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

调用 filterFunction once for each item from begin to end 。若 filterFunction 返回 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 返回 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 。若 reduceOptions is QtConcurrent::OrderedReduce reduceFunction is called in the order of the original sequence.

注意: 此函数将阻塞,直到迭代器到达正处理序列的末尾。

另请参阅 filteredReduced () 和 并发过滤和过滤缩减 .

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

调用 function once for each item in sequence function is passed a reference to the item, so that any modifications done to the item will appear in sequence .

注意: 此函数将阻塞,直到已处理所有序列项。

另请参阅 map () 和 并发映射和映射缩减 .

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

调用 function once for each item from begin to end function is passed a reference to the item, so that any modifications done to the item will appear in the sequence which the iterators belong to.

注意: 此函数将阻塞,直到迭代器到达正处理序列的末尾。

另请参阅 map () 和 并发映射和映射缩减 .

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

调用 function once for each item in sequence and returns a Sequence containing the results. The type of the results will match the type returned my the MapFunction.

注意: 此函数将阻塞,直到已处理所有序列项。

另请参阅 mapped () 和 并发映射和映射缩减 .

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

调用 function once for each item from begin to end and returns a container with the results. Specify the type of container as the a template argument, like this:

QList<int> ints = QtConcurrent::blockingMapped<QList<int> >(beginIterator, endIterator, fn);
					

注意: 此函数将阻塞,直到迭代器到达正处理序列的末尾。

另请参阅 mapped () 和 并发映射和映射缩减 .

T QtConcurrent:: blockingMappedReduced (const Sequence & sequence , MapFunction mapFunction , ReduceFunction reduceFunction , QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce)

调用 mapFunction once for each item in sequence . The return value of each mapFunction 会被传递给 reduceFunction .

Note that while mapFunction is called concurrently, only one thread at a time will call reduceFunction . The order in which reduceFunction is called is determined by reduceOptions .

注意: 此函数将阻塞,直到已处理所有序列项。

另请参阅 mapped () 和 并发映射和映射缩减 .

T QtConcurrent:: blockingMappedReduced ( ConstIterator begin , ConstIterator end , MapFunction mapFunction , ReduceFunction reduceFunction , QtConcurrent::ReduceOptions reduceOptions = UnorderedReduce | SequentialReduce)

调用 mapFunction once for each item from begin to end . The return value of each mapFunction 会被传递给 reduceFunction .

Note that while mapFunction is called concurrently, only one thread at a time will call reduceFunction . The order in which reduceFunction is called is undefined.

注意: 此函数将阻塞,直到迭代器到达正处理序列的末尾。

另请参阅 blockingMappedReduced () 和 并发映射和映射缩减 .

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

调用 filterFunction once for each item in sequence 。若 filterFunction 返回 true , the item is kept in sequence ; otherwise, the item is removed from sequence .

另请参阅 并发过滤和过滤缩减 .

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

调用 filterFunction once for each item in sequence and returns a new Sequence of kept items. If filterFunction 返回 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 )

调用 filterFunction once for each item from begin to end and returns a new Sequence of kept items. If filterFunction 返回 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)

调用 filterFunction once for each item in sequence 。若 filterFunction 返回 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 返回 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 。若 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)

调用 filterFunction once for each item from begin to end 。若 filterFunction 返回 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 返回 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 。若 reduceOptions is QtConcurrent::OrderedReduce reduceFunction is called in the order of the original sequence.

另请参阅 并发过滤和过滤缩减 .

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

调用 function once for each item in sequence function is passed a reference to the item, so that any modifications done to the item will appear in sequence .

另请参阅 并发映射和映射缩减 .

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

调用 function once for each item from begin to end function is passed a reference to the item, so that any modifications done to the item will appear in the sequence which the iterators belong to.

另请参阅 并发映射和映射缩减 .

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

调用 function once for each item in sequence and returns a future with each mapped item as a result. You can use QFuture::const_iterator or QFutureIterator to iterate through the results.

另请参阅 并发映射和映射缩减 .

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

调用 function once for each item from begin to end and returns a future with each mapped item as a result. You can use QFuture::const_iterator or QFutureIterator to iterate through the results.

另请参阅 并发映射和映射缩减 .

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

调用 mapFunction once for each item in sequence . The return value of each mapFunction 会被传递给 reduceFunction .

Note that while mapFunction is called concurrently, only one thread at a time will call reduceFunction . The order in which reduceFunction is called is determined by reduceOptions .

另请参阅 并发映射和映射缩减 .

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

调用 mapFunction once for each item from begin to end . The return value of each mapFunction 会被传递给 reduceFunction .

Note that while mapFunction is called concurrently, only one thread at a time will call reduceFunction . By default, the order in which reduceFunction is called is undefined.

注意: QtConcurrent::OrderedReduce results in the ordered reduction.

另请参阅 并发映射和映射缩减 .

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

相当于

QtConcurrent::run(QThreadPool::globalInstance(), function, ...);
					

运行 function in a separate thread. The thread is taken from the global QThreadPool 。注意, function may not run immediately; function will only be run once a thread becomes available.

T is the same type as the return value of function . Non-void return values can be accessed via the QFuture::result () 函数。

注意, QFuture returned by QtConcurrent::run() does not support canceling, pausing, or progress reporting. The QFuture returned can only be used to query for the running/finished status and the return value of the function.

另请参阅 并发运行 .

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

运行 function in a separate thread. The thread is taken from the QThreadPool pool 。注意, function may not run immediately; function will only be run once a thread becomes available.

T is the same type as the return value of function . Non-void return values can be accessed via the QFuture::result () 函数。

注意, QFuture returned by QtConcurrent::run() does not support canceling, pausing, or progress reporting. The QFuture returned can only be used to query for the running/finished status and the return value of the function.

该函数在 Qt 5.4 引入。

另请参阅 并发运行 .