开启新线程QFeature和QFatureWatcher的使用
作者:互联网
示例:
ui->listWidget->clear();
QString saveDir = ui->lineEdit_path->text();
if(saveDir.isEmpty())
{
QMessageBox::information(this,QString::fromLocal8Bit("提示"),QString::fromLocal8Bit("输出路径不为空"));
return;
}
//监控线程结束的信号
QFeatureWatcher<int>* watcher = new QFeatureWatcher<int>;
connect(watcher, &QFeatureWatcher<int>::finished, [=](){
ui->listWidget->addItem(QString::fromLocal8Bit("%1 成功").arg(QDateTime::currentDateTime().toString("hh:mm:ss.zzz")));
ui->pushButton_ok->setEnabled(true);
watcher->deleteLater();
});
ui->listWidget->addItem(QString::fromLocal8Bit("%1 正在处理...").arg(QDateTime::currentDateTime().toString("hh:mm:ss.zzz")));
ui->pushButton_ok->setEnabled(false);
//开启新线程
QFeature<int> feature = QtConcurrent::run([=]{
if(ui->radioButton_excel->isChecked())
extractData("xlsx",saveDir); //执行耗时操作
else if()
extractData("txt",saveDir);
else if()
extractData("shp",saveDir);
return 0;
});
标签:extractData,watcher,fromLocal8Bit,saveDir,ui,QFeature,线程,QFatureWatcher,QString 来源: https://blog.csdn.net/Superman___007/article/details/122288462