头文件
#include <QtConcurrent/QtConcurrentRun>
表达式方式
QtConcurrent::run([=]() { // 需要执行的代码 });
执行完触发槽函数
#include <QFutureWatcher> #include <QtConcurrent/QtConcurrentRun> QFutureWatcher<void> *pwatcher = new QFutureWatcher<void>; connect(pwatcher, &QFutureWatcher<void>::finished, this, [=]() { // 执行完后触发该槽函数 }); QFuture<void> future = QtConcurrent::run([=]() { // 需要执行的代码 }); pwatcher->setFuture(future);
转自:https://blog.csdn.net/weixin_45118705/article/details/105760727