企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[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); } } ```