QFutureWatcher 信号不工作
QFutureWatcher signal not working
我的函数 finishedCopy() 在 QtConcurrent::run 函数 copyFolder 完成时未被调用。 copyFolder 函数确实完成了 w/o 个错误。
QFutureWatcher<void> watcher;
connect(&watcher, SIGNAL(finished()), this, SLOT(MainWindow::finishedCopy()));
QFuture <void> future = QtConcurrent::run(this,&MainWindow::copyFolder,filepath,dir);
watcher.setFuture(future);
void MainWindow::finishedCopy()
{
QMessageBox::information(this,"","Done");
}
替换为:
connect(&watcher, SIGNAL(finished()), this, SLOT(MainWindow::finishedCopy()));
这样:
connect(&watcher, SIGNAL(finished()), this, SLOT(finishedCopy()));
此外,connect
returns bool
这样您就可以随时检查连接是否成功。
你需要你的观察者活得更久..你在堆栈中声明你的观察者,所以它会在连接信号发出之前被销毁。
尝试在 MainWindow 中将 QFutureWatcher 观察器声明为成员变量header,然后将单个连接到 MainWindow 构造函数中的插槽
我的函数 finishedCopy() 在 QtConcurrent::run 函数 copyFolder 完成时未被调用。 copyFolder 函数确实完成了 w/o 个错误。
QFutureWatcher<void> watcher;
connect(&watcher, SIGNAL(finished()), this, SLOT(MainWindow::finishedCopy()));
QFuture <void> future = QtConcurrent::run(this,&MainWindow::copyFolder,filepath,dir);
watcher.setFuture(future);
void MainWindow::finishedCopy()
{
QMessageBox::information(this,"","Done");
}
替换为:
connect(&watcher, SIGNAL(finished()), this, SLOT(MainWindow::finishedCopy()));
这样:
connect(&watcher, SIGNAL(finished()), this, SLOT(finishedCopy()));
此外,connect
returns bool
这样您就可以随时检查连接是否成功。
你需要你的观察者活得更久..你在堆栈中声明你的观察者,所以它会在连接信号发出之前被销毁。
尝试在 MainWindow 中将 QFutureWatcher 观察器声明为成员变量header,然后将单个连接到 MainWindow 构造函数中的插槽