其他分享
首页 > 其他分享> > Qt中运行后台线程不阻塞UI线程的方案

Qt中运行后台线程不阻塞UI线程的方案

作者:互联网

然后创建一个QThread线程,把整个MyTaskClass类的实例move到线程中就可以了:

#include <QtWidgets/QApplication>
#include <QThread>
#include "MyTaskClass.hpp"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QThread* backgroundThread = new QThread;
    backgroundThread->start();

     MyTaskClass *task = new MyTaskClass();
     task->moveToThread(backgroundThread);

    MainWindow w;
    w.show();
    return a.exec();
}

标签:backgroundThread,Qt,int,UI,MyTaskClass,线程,include,QThread
来源: https://blog.csdn.net/weixin_47556699/article/details/118268861