在我的应用程序中,我在对话框中有以下代码:
connect(drive, SIGNAL(FileProgressChanged(Progress)), SLOT(OnFileProgressChanged(Progress)));
QtConcurrent::run(this, &ProgressDialog::PerformOperation, Operation, *Path, OutPath, drive);
PerformOperation 函数最终会调用一个drive
发出信号的函数FileProgressChanged
,我的OnFileProgressChanged
函数如下:
void ProgressDialog::OnFileProgressChanged(Progress p)
{
if (ui->progressCurrent->maximum() != p.Maximium)
ui->progressCurrent->setMaximum(p.Maximium);
ui->progressCurrent->setValue(p.Current);
if (ui->groupBoxCurrent->title().toStdString() != p.FilePath)
ui->groupBoxCurrent->setTitle(QString::fromStdString(p.FilePath));
}
我正在阅读并看到QFuture和QFutureWatcher支持监视进度值(这在这种情况下会很好用!),但它们不能与QtConcurrent::run
.
我将如何将在单独线程上发出的移动信号连接到我的主线程上的插槽,以便我可以监视在发射器线程上调用的函数的进度?
*编辑 -- *我实际上发现我的代码有一个错误,但它似乎没有影响。我忘了在信号后添加this
作为参数
connect(drive, SIGNAL(FileProgressChanged(Progress)), this, SLOT(OnFileProgressChanged(Progress)));