简介
QtConcurrent是针对qt中多线程相关的高层封装,如QFuture
结构
Qtconcurrent命名空间中的run支持的有
其对应的functor下结构为
类关系
functor对应的类核心关系为
RunFunctionTaskBase
- start():默认使用的是全局线程池
QFuture<T> start(QThreadPool* poll)
{
this->setThreadPool(pool);
this->setRunnable(this);
this->reportStarted();
QFuture<T> theFuture = this->future();
pool->start(this, 0);
return theFuture;
}
- run():是空实现
void run() {}
- runFunctor():纯虚函数
virtual void runFunctor() = 0;
RunFunctionTask
是整个QtConcurrent::run执行框架
其重写了QRunnable的run方法,执行runFunctor
template <typename T>
class RunFunctionTask : public RunFunctionTaskBase<T>
{
public:
void run() override
{
if (this->isCancelled()) {
this->reportFinished();
return;
}
#ifndef QT_NO_EXCEPTIONS
try {
#endif
this->runFunctor();
#ifndef QT_NO_EXCEPTIONS
} catch(QException& e) {
QFutureInterface<T>::reportException(e);
} catch(...) {
QFutureInferface<T>::reportException(QUnhandledException());
}
#endif
this->reportResult(result);
this->reportFinished();
}
};