🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] ## QtConcurrent 使用时,需要在 .pro 文件中添加 模块 ``` QT += core gui concurrent ``` ## 示例 ### Run 方法 ``` void Hello(QString msg){ qDebug()<<msg; QThread::sleep(2); qDebug()<<QThread::currentThreadId(); } QFuture<void> f1 = QtConcurrent::run(Hello,QString("hell")); QFuture<void> f2 = QtConcurrent::run(Hello,QString("word")); f1.waitForFinished(); f2.waitForFinished(); ``` ### 类方法 ``` QtConcurrent::run(QThreadPool::globalInstance(),this, &QtWidgetsApplication1::hello); void QtWidgetsApplication1::hello() { for (int i = 0; i < 3; ++i) { qDebug() << "hello world"; QThread::sleep(1); } } ```