开启新线程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;
    });

上一篇:线性回归


下一篇:VS2019+qt string,QString中文乱码问题解决及string转换为QString时中文乱码问题