CopperSpice API  1.9.2
Concurrent Programming

The QtConcurrent namespace provides high-level APIs that make it possible to write multi-threaded programs without using low-level threading primitives such as mutexes, read-write locks, wait conditions, or semaphores. Programs written with QtConcurrent automatically adjust the number of threads used according to the number of processor cores available. This means that applications written today will continue to scale when deployed on multi-core systems in the future.

QtConcurrent includes functional programming style APIs for parallel list processing, including a MapReduce and FilterReduce implementation for shared-memory (non-distributed) systems, and classes for managing asynchronous computations in GUI applications:

QtConcurrent supports several container and iterator types, but works best with containers which have random access iterators like QList or QVector. The map and filter functions accept both containers and begin/end iterators.

Iterator TypeExample classesSupport status
Input Iterator Not Supported
Output Iterator Not Supported
Forward Iterator std::slist Supported
Bidirectional Iterator QLinkedList Supported
Random Access Iterator QList, QVector Supported and Recommended

Random access iterators can be faster in cases where QtConcurrent is iterating over a large number of lightweight items, since they allow skipping to any point in the container. In addition, using random access iterators allows QtConcurrent to provide progress information through QFuture::progressValue() and QFutureWatcher::progressValueChanged().

The non in-place modifying functions such as mapped() and filtered() make a copy of the container. This copy operation might be slow. It may be faster to specify the begin and end iterators for the container.