当完成QtConcurrent::run函数copyFolder时,不会调用我的函数finishedCopy()。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");
}发布于 2016-10-07 05:05:30
你需要你的守望者活得更长。您正在声明堆栈中的监视程序,因此在发出连接信号之前,它将被销毁。
尝试将QFutureWatcher观察者声明为MainWindow标头中的成员变量,然后将其连接到MainWindow构造函数中的插槽。
发布于 2016-10-07 03:59:18
代之以:
connect(&watcher, SIGNAL(finished()), this, SLOT(MainWindow::finishedCopy()));在此基础上:
connect(&watcher, SIGNAL(finished()), this, SLOT(finishedCopy()));另外,connect返回bool,这样您就可以始终检查连接是否成功。
https://stackoverflow.com/questions/39909068
复制相似问题