知识库

wiki.linsakura.com

用户工具

站点工具


wiki:dev:qt:note:qfuture

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

后一修订版
前一修订版
wiki:dev:qt:note:qfuture [2026/10/13 10:31]
博丽幻月 创建
wiki:dev:qt:note:qfuture [2026/10/13 10:34] (当前版本)
博丽幻月
行 1: 行 1:
 ====== QFuture用法 ====== ====== QFuture用法 ======
 +首先添加头文件
 <code cpp> <code cpp>
 +#include <QtConcurrent/QtConcurrent>
 +#include <QFutureWatcher>
 +</code>
 +然后
 +<code cpp>
 +    // 使用 QFutureWatcher 监听完成事件
 +    QFutureWatcher<void> *watcher = new QFutureWatcher<void>(this);
 +    connect(watcher, &QFutureWatcher<void>::finished, this, [this, watcher](){
 +        watcher->deleteLater();
 +        // 完成后需要执行的内容
 +    });
 +
 +    // 将同步函数放到线程池中异步执行
 +    QFuture<void> future = QtConcurrent::run([](){
 +        // 需要异步执行的内容
 +    });
 +
 +    watcher->setFuture(future);
 </code> </code>
wiki/dev/qt/note/qfuture.1791858702.txt.gz · 最后更改: 2026/10/13 10:31 由 博丽幻月