Qt 线程操作

方法一:movetothread

将对象移入子线程,通过信号槽来分配任务以及信息传递,这也是Qt推荐的做法。

    auto thread = new QThread();
    auto sbsImporter = new SoloSbsImporter();
    sbsImporter->moveToThread(thread); 
    connect(this, SIGNAL(importSBSLogFiles(QStringList)), sbsImporter, SLOT(processSBSLogFiles(QStringList)));
    connect(sbsImporter, SIGNAL(logMessageSG(QString)), this, SLOT(logMessageSL(QString)));
    connect(sbsImporter, SIGNAL(resetProgressBarSG(qint32, qint32, QString)), this, SLOT(resetProgressBarSL(qint32 , qint32 , QString )));
    connect(sbsImporter, SIGNAL(setProgressBarValueSG(qint32)), this, SLOT(setProgressBarValueSL(qint32)));
    connect(sbsImporter, &SoloSbsImporter::importSbsfilesFinishSG, myShotGatherTableView, &SoloShotGatherTableView::dataChanged);
    connect(thread, SIGNAL(finished()), sbsImporter, SLOT(deleteLater()));
    thread->start();


方法二:使用Class QThread

重写 run()函数即可。


方法三:QThreadPool

线程池操作


方法四:并发处理 QtConcurrent

链接:https://blog.csdn.net/qq_27175513/article/details/80077982


根据需求可选取不同的方式进行多线程操作。

猜你喜欢

转载自blog.csdn.net/qq_27175513/article/details/80076258