QtConcurrent 名稱空間

The QtConcurrent 名稱空間提供高級 API 使之可能不使用低級綫程原語,編寫多綫程程序。 更多...

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

class IntermediateResults

類型

enum ReduceOption { UnorderedReduce, OrderedReduce, SequentialReduce }
flags ReduceOptions

函數

void blockingFilter (Sequence & sequence , KeepFunctor filterFunction )
Sequence blockingFiltered (const Sequence & sequence , KeepFunctor filterFunction )
OutputSequence blockingFiltered (Iterator begin , Iterator end , KeepFunctor filterFunction )
ResultType blockingFilteredReduced (const Sequence & sequence , KeepFunctor filterFunction , ReduceFunctor reduceFunction , QtConcurrent::ReduceOptions reduceOptions = ReduceOptions(UnorderedReduce | SequentialReduce))
ResultType blockingFilteredReduced (Iterator begin , Iterator end , KeepFunctor filterFunction , ReduceFunctor reduceFunction , QtConcurrent::ReduceOptions reduceOptions = ReduceOptions(UnorderedReduce | SequentialReduce))
void blockingMap (Sequence & sequence , MapFunctor function )
void blockingMap (Iterator begin , Iterator end , MapFunctor function )
OutputSequence blockingMapped (const InputSequence & sequence , MapFunctor function )
Sequence blockingMapped (Iterator begin , Iterator end , MapFunctor function )
ResultType blockingMappedReduced (const Sequence & sequence , MapFunctor mapFunction , ReduceFunctor reduceFunction , QtConcurrent::ReduceOptions reduceOptions = ReduceOptions(UnorderedReduce | SequentialReduce))
ResultType blockingMappedReduced (Iterator begin , Iterator end , MapFunctor mapFunction , ReduceFunctor reduceFunction , QtConcurrent::ReduceOptions reduceOptions = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce))
QFuture<void> filter (Sequence & sequence , KeepFunctor filterFunction )
QFuture<typename Sequence::value_type> filtered (const Sequence & sequence , KeepFunctor filterFunction )
QFuture<typename qValueType<Iterator>::value_type> filtered (Iterator begin , Iterator end , KeepFunctor filterFunction )
QFuture<ResultType> filteredReduced (const Sequence & sequence , KeepFunctor filterFunction , ReduceFunctor reduceFunction , QtConcurrent::ReduceOptions reduceOptions = ReduceOptions(UnorderedReduce | SequentialReduce))
QFuture<ResultType> filteredReduced (Iterator begin , Iterator end , KeepFunctor filterFunction , ReduceFunctor reduceFunction , QtConcurrent::ReduceOptions reduceOptions = ReduceOptions(UnorderedReduce | SequentialReduce))
QFuture<void> map (Sequence & sequence , MapFunctor function )
QFuture<void> map (Iterator begin , Iterator end , MapFunctor function )
QFuture<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType> mapped (const Sequence & sequence , MapFunctor function )
QFuture<typename QtPrivate::MapResultType<void, MapFunctor>::ResultType> mapped (Iterator begin , Iterator end , MapFunctor function )
QFuture<ResultType> mappedReduced (const Sequence & sequence , MapFunctor mapFunction , ReduceFunctor reduceFunction , QtConcurrent::ReduceOptions reduceOptions = ReduceOptions(UnorderedReduce | SequentialReduce))
QFuture<ResultType> mappedReduced (Iterator begin , Iterator end , MapFunctor mapFunction , ReduceFunctor reduceFunction , QtConcurrent::ReduceOptions reduceOptions = ReduceOptions(UnorderedReduce | SequentialReduce))
QFuture<T> run (Function function , ... )
QFuture<T> run (QThreadPool * pool , Function function , ... )

詳細描述

The QtConcurrent 名稱空間提供高級 API 使之可能不使用低級綫程原語,編寫多綫程程序。

Qt Concurrent 模塊文檔編製瞭解可用函數的概述,或見下文瞭解每個函數的詳細信息。

class IntermediateResults

類型文檔編製

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 , KeepFunctor 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 , KeepFunctor 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 () 和 並發過濾和過濾縮減 .

OutputSequence QtConcurrent:: blockingFiltered ( Iterator begin , Iterator end , KeepFunctor 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 () 和 並發過濾和過濾縮減 .

ResultType QtConcurrent:: blockingFilteredReduced (const Sequence & sequence , KeepFunctor filterFunction , ReduceFunctor reduceFunction , QtConcurrent::ReduceOptions 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 () 和 並發過濾和過濾縮減 .

ResultType QtConcurrent:: blockingFilteredReduced ( Iterator begin , Iterator end , KeepFunctor filterFunction , ReduceFunctor reduceFunction , QtConcurrent::ReduceOptions 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 , MapFunctor 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 , MapFunctor 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 () 和 並發映射和映射縮減 .

OutputSequence QtConcurrent:: blockingMapped (const InputSequence & sequence , MapFunctor function )

調用 function once for each item in sequence and returns an OutputSequence containing the results. The type of the results will match the type returned my the MapFunctor.

注意: 此函數將阻塞,直到已處理所有序列項。

另請參閱 mapped () 和 並發映射和映射縮減 .

Sequence QtConcurrent:: blockingMapped ( Iterator begin , Iterator end , MapFunctor 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 () 和 並發映射和映射縮減 .

ResultType QtConcurrent:: blockingMappedReduced (const Sequence & sequence , MapFunctor mapFunction , ReduceFunctor reduceFunction , QtConcurrent::ReduceOptions 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 () 和 並發映射和映射縮減 .

ResultType QtConcurrent:: blockingMappedReduced ( Iterator begin , Iterator end , MapFunctor mapFunction , ReduceFunctor reduceFunction , QtConcurrent::ReduceOptions reduceOptions = QtConcurrent::ReduceOptions(QtConcurrent::UnorderedReduce | QtConcurrent::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 , KeepFunctor filterFunction )

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

另請參閱 並發過濾和過濾縮減 .

QFuture < typename Sequence::value_type > QtConcurrent:: filtered (const Sequence & sequence , KeepFunctor 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 < typename qValueType < Iterator > ::value_type > QtConcurrent:: filtered ( Iterator begin , Iterator end , KeepFunctor 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 < ResultType > QtConcurrent:: filteredReduced (const Sequence & sequence , KeepFunctor filterFunction , ReduceFunctor reduceFunction , QtConcurrent::ReduceOptions 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 < ResultType > QtConcurrent:: filteredReduced ( Iterator begin , Iterator end , KeepFunctor filterFunction , ReduceFunctor reduceFunction , QtConcurrent::ReduceOptions 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 , MapFunctor 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 , MapFunctor 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 < typename QtPrivate::MapResultType < void , MapFunctor > ::ResultType > QtConcurrent:: mapped (const Sequence & sequence , MapFunctor 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 < typename QtPrivate::MapResultType < void , MapFunctor > ::ResultType > QtConcurrent:: mapped ( Iterator begin , Iterator end , MapFunctor 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 < ResultType > QtConcurrent:: mappedReduced (const Sequence & sequence , MapFunctor mapFunction , ReduceFunctor reduceFunction , QtConcurrent::ReduceOptions 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 < ResultType > QtConcurrent:: mappedReduced ( Iterator begin , Iterator end , MapFunctor mapFunction , ReduceFunctor reduceFunction , QtConcurrent::ReduceOptions 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 () 函數。

注意: The QFuture returned can only be used to query for the running/finished status and the return value of the function. In particular, canceling or pausing can be issued only if the computations behind the future has not been started.

另請參閱 並發運行 .

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 () 函數。

注意: The QFuture returned can only be used to query for the running/finished status and the return value of the function. In particular, canceling or pausing can be issued only if the computations behind the future has not been started.

該函數在 Qt 5.4 引入。

另請參閱 並發運行 .