QtConcurrent Namespace

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

  1. #include <QtCore>

This namespace was introduced in Qt 4.4.

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.

Public Types

Toggle detailsenum QtConcurrent::

ReduceOptionReduceOption { UnorderedReduce , OrderedReduce , SequentialReduce 0x4 ...} { UnorderedReduce , OrderedReduce , SequentialReduce 0x4 }

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

ConstantValueDescription
QtConcurrent::UnorderedReduce 0x1 Reduction is done in an arbitrary order.
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.)

Look up this member in the source code.

    Public Functions

    Toggle details void QtConcurrent

    blockingFilterblockingFilter ( Sequence &sequence , FilterFunctionfilterFunction ...) ( Sequence &sequence , FilterFunctionfilterFunction )

    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.

    Look up this member in the source code.

    Toggle details Sequence QtConcurrent

    blockingFilteredblockingFiltered ( const Sequence &sequence , FilterFunctionfilterFunction ...) ( const Sequence &sequence , FilterFunctionfilterFunction )

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

    Look up this member in the source code.

    Toggle details Sequence QtConcurrent

    blockingFilteredblockingFiltered ( ConstIteratorbegin , ConstIteratorend , FilterFunctionfilterFunction ...) ( ConstIteratorbegin , ConstIteratorend , FilterFunctionfilterFunction )

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

    Look up this member in the source code.

    Toggle details T QtConcurrent

    blockingFilteredReducedblockingFilteredReduced ( const Sequence &sequence , FilterFunctionfilterFunction , ReduceFunctionreduceFunction , QtConcurrent::ReduceOptions reduceOptions=UnorderedReduce | SequentialReduce ...) ( const Sequence &sequence , FilterFunctionfilterFunction , ReduceFunctionreduceFunction , 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().

    Look up this member in the source code.

    Toggle details T QtConcurrent

    blockingFilteredReducedblockingFilteredReduced ( ConstIteratorbegin , ConstIteratorend , FilterFunctionfilterFunction , ReduceFunctionreduceFunction , QtConcurrent::ReduceOptions reduceOptions=UnorderedReduce | SequentialReduce ...) ( ConstIteratorbegin , ConstIteratorend , FilterFunctionfilterFunction , ReduceFunctionreduceFunction , 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().

    Look up this member in the source code.

    Toggle details void QtConcurrent

    blockingMapblockingMap ( Sequence &sequence , MapFunctionfunction ...) ( Sequence &sequence , MapFunctionfunction )

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

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

    See also map().

    Look up this member in the source code.

    Toggle details void QtConcurrent

    blockingMapblockingMap ( Iteratorbegin , Iteratorend , MapFunctionfunction ...) ( Iteratorbegin , Iteratorend , MapFunctionfunction )

    Calls function once for each item from begin to end. The 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.

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

    See also map().

    Look up this member in the source code.

    Toggle details T QtConcurrent

    blockingMappedblockingMapped ( const Sequence &sequence , MapFunctionfunction ...) ( const Sequence &sequence , MapFunctionfunction )

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

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

    See also mapped().

    Look up this member in the source code.

    Toggle details T QtConcurrent

    blockingMappedblockingMapped ( ConstIteratorbegin , ConstIteratorend , MapFunctionfunction ...) ( ConstIteratorbegin , ConstIteratorend , MapFunctionfunction )

    Calls 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:

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

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

    See also mapped().

    Look up this member in the source code.

    Toggle details T QtConcurrent

    blockingMappedReducedblockingMappedReduced ( const Sequence &sequence , MapFunctionmapFunction , ReduceFunctionreduceFunction , QtConcurrent::ReduceOptions reduceOptions=UnorderedReduce | SequentialReduce ...) ( const Sequence &sequence , MapFunctionmapFunction , ReduceFunctionreduceFunction , QtConcurrent::ReduceOptions reduceOptions=UnorderedReduce | SequentialReduce )

    Calls mapFunction once for each item in sequence. The return value of each mapFunction is passed to 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.

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

    See also mapped().

    Look up this member in the source code.

    Toggle details T QtConcurrent

    blockingMappedReducedblockingMappedReduced ( ConstIteratorbegin , ConstIteratorend , MapFunctionmapFunction , ReduceFunctionreduceFunction , QtConcurrent::ReduceOptions reduceOptions=UnorderedReduce | SequentialReduce ...) ( ConstIteratorbegin , ConstIteratorend , MapFunctionmapFunction , ReduceFunctionreduceFunction , QtConcurrent::ReduceOptions reduceOptions=UnorderedReduce | SequentialReduce )

    Calls mapFunction once for each item from begin to end. The return value of each mapFunction is passed to 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.

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

    See also blockingMappedReduced().

    Look up this member in the source code.

    Toggle details QFuture <void> QtConcurrent

    filterfilter ( Sequence &sequence , FilterFunctionfilterFunction ...) ( Sequence &sequence , FilterFunctionfilterFunction )

    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.

    Look up this member in the source code.

    Toggle details QFuture <T> QtConcurrent

    filteredfiltered ( const Sequence &sequence , FilterFunctionfilterFunction ...) ( const Sequence &sequence , FilterFunctionfilterFunction )

    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.

    Look up this member in the source code.

    Toggle details QFuture <T> QtConcurrent

    filteredfiltered ( ConstIteratorbegin , ConstIteratorend , FilterFunctionfilterFunction ...) ( ConstIteratorbegin , ConstIteratorend , FilterFunctionfilterFunction )

    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.

    Look up this member in the source code.

    Toggle details QFuture <T> QtConcurrent

    filteredReducedfilteredReduced ( const Sequence &sequence , FilterFunctionfilterFunction , ReduceFunctionreduceFunction , QtConcurrent::ReduceOptions reduceOptions=UnorderedReduce | SequentialReduce ...) ( const Sequence &sequence , FilterFunctionfilterFunction , ReduceFunctionreduceFunction , 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.

    Look up this member in the source code.

    Toggle details QFuture <T> QtConcurrent

    filteredReducedfilteredReduced ( ConstIteratorbegin , ConstIteratorend , FilterFunctionfilterFunction , ReduceFunctionreduceFunction , QtConcurrent::ReduceOptions reduceOptions=UnorderedReduce | SequentialReduce ...) ( ConstIteratorbegin , ConstIteratorend , FilterFunctionfilterFunction , ReduceFunctionreduceFunction , 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.

    Look up this member in the source code.

    Toggle details QFuture <void> QtConcurrent

    mapmap ( Sequence &sequence , MapFunctionfunction ...) ( Sequence &sequence , MapFunctionfunction )

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

    Look up this member in the source code.

    Toggle details QFuture <void> QtConcurrent

    mapmap ( Iteratorbegin , Iteratorend , MapFunctionfunction ...) ( Iteratorbegin , Iteratorend , MapFunctionfunction )

    Calls function once for each item from begin to end. The 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.

    Look up this member in the source code.

    Toggle details QFuture <T> QtConcurrent

    mappedmapped ( const Sequence &sequence , MapFunctionfunction ...) ( const Sequence &sequence , MapFunctionfunction )

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

    Look up this member in the source code.

    Toggle details QFuture <T> QtConcurrent

    mappedmapped ( ConstIteratorbegin , ConstIteratorend , MapFunctionfunction ...) ( ConstIteratorbegin , ConstIteratorend , MapFunctionfunction )

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

    Look up this member in the source code.

    Toggle details QFuture <T> QtConcurrent

    mappedReducedmappedReduced ( const Sequence &sequence , MapFunctionmapFunction , ReduceFunctionreduceFunction , QtConcurrent::ReduceOptions reduceOptions=UnorderedReduce | SequentialReduce ...) ( const Sequence &sequence , MapFunctionmapFunction , ReduceFunctionreduceFunction , QtConcurrent::ReduceOptions reduceOptions=UnorderedReduce | SequentialReduce )

    Calls mapFunction once for each item in sequence. The return value of each mapFunction is passed to 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.

    Look up this member in the source code.

    Toggle details QFuture <T> QtConcurrent

    mappedReducedmappedReduced ( ConstIteratorbegin , ConstIteratorend , MapFunctionmapFunction , ReduceFunctionreduceFunction , QtConcurrent::ReduceOptions reduceOptions=UnorderedReduce | SequentialReduce ...) ( ConstIteratorbegin , ConstIteratorend , MapFunctionmapFunction , ReduceFunctionreduceFunction , QtConcurrent::ReduceOptions reduceOptions=UnorderedReduce | SequentialReduce )

    Calls mapFunction once for each item from begin to end. The return value of each mapFunction is passed to 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.

    Note: QtConcurrent::OrderedReduce results in the ordered reduction.

    Look up this member in the source code.

    Toggle details QFuture <T> QtConcurrent

    runrun ( Functionfunction , ... ) ( Functionfunction , ... )

    Runs function in a separate thread. The thread is taken from the global QThreadPool. Note that the function may not run immediately; the function will only be run when a thread is available.

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

    Note that the 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.

    Look up this member in the source code.

      Notes provided by the Qt Community
      Informative
      • 5

      Votes: 6

      Coverage: Qt library 4.8, 4.7, 5.0

      Picture of daviddoria daviddoria

      Lab Rat
      6 notes

      Examples

      How to call a member function:
      http://developer.qt.nokia.com/wiki/QtConcurrent-run-member-function

      How to call an inherited member function:
      http://developer.qt.nokia.com/wiki/QtConcurrent-run-inherited-member-function

      How to call a member function on each item in the container that is being iterated:
      http://developer.qt.nokia.com/wiki/QtConcurrent-BlockingMap-Member-Function-of-iterated-objects

      How to call a member function on each item in the container that is being iterated and get a container of the return values:
      http://developer.qt.nokia.com/wiki/QtConcurrent-BlockingMapped-Member-Function-of-iterated-objects

      How to call a member function of a different class instance on each item in the container (by overloading operator() ) and get a container of the return values:
      http://developer.qt.nokia.com/wiki/QtConcurrent-BlockingMapped-Other-Object-Member-Function-Operator

      How to call a member function of a different class instance on each item in the container (using boost::bind) and get a container of the return values:
      http://developer.qt.nokia.com/wiki/QtConcurrent-BlockingMapped-Other-Object-Member-Function-Bind

      [Revisions]

      Informative
      • 4

      Votes: 3

      Coverage: Qt library 4.7, 4.8, qt 5.0

      Picture of peppe peppe

      Ant Farmer
      8 notes

      Better explainations available in official docs!

      This doc page is quite unfortunate.

      It looks like an ordinary doc page, but it has unique features; namely, the links to the functions don’t link to anchors in this page, but they link to other pages in which you can find much more information, examples, explainations, etc.!

      For instance:

      Please use those pages as reference documentation for QtConcurrent!

      [Revisions]