Thread Support in Qt

Qt 提供独立于平台的线程类, 线程安全的事件发布方式, 及跨线程的信号槽连接的形式. 这使得开发可移植的多线程 Qt 应用程序和利用多处理器机器变得容易. 多线程编程也是一种有用的范例, 可以在不阻塞应用程序用户界面的情况下执行耗时的操作.

Qt 的早期版本提供了在没有线程支持的情况下构建库的选项. 从 Qt 4.0 开始, 线程始终处于启用状态.

主题:

下列文章假设读者具有有关多线程应用程序的基本知识.

The Threading Classes

下列类与线程相关.

Concurrent Filter and Filter-Reduce

Concurrent Map and Map-Reduce

Concurrent Run

QtConcurrent

High-level APIs that make it possible to write multi-threaded programs without using low-level threading primitives

QAtomicInteger

Platform-independent atomic operations on integers

QAtomicPointer

Template class that provides platform-independent atomic operations on pointers

QFuture

Represents the result of an asynchronous computation

QFutureSynchronizer

Convenience class that simplifies QFuture synchronization

QFutureWatcher

Allows monitoring a QFuture using signals and slots

QMutex

Access serialization between threads

QMutexLocker

Convenience class that simplifies locking and unlocking mutexes

QReadLocker

Convenience class that simplifies locking and unlocking read-write locks for read access

QReadWriteLock

Read-write locking

QWriteLocker

Convenience class that simplifies locking and unlocking read-write locks for write access

QRunnable

The base class for all runnable objects

QSemaphore

General counting semaphore

QThread

Platform-independent way to manage threads

QThreadPool

Manages a collection of QThreads

QThreadStorage

Per-thread data storage

QWaitCondition

Condition variable for synchronizing threads

注意: Qt 的线程类是使用本地平台的线程 API 实现的; 如., Win32 和 pthreads. 因此, 它们可以与相同平台 API 的线程一起使用.