QFutureWatcher信号不工作
QFutureWatcher signal not working
当QtConcurrent::run函数copyFolder完成时,我的函数finishedCopy()没有被调用。copyFolder函数没有错误。
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");
}
你需要你的手表更长寿。你在堆栈中声明了你的监视程序,所以它会在连接信号发出之前被销毁。
尝试声明QFutureWatcher watcher作为MainWindow头中的成员变量,然后将单个连接到MainWindow构造函数
替换为
connect(&watcher, SIGNAL(finished()), this, SLOT(MainWindow::finishedCopy()));
与:connect(&watcher, SIGNAL(finished()), this, SLOT(finishedCopy()));
此外,connect
返回bool
,因此您可以始终检查连接是否成功。
相关文章:
- C++ 信号和插槽不工作:插槽不响应事件
- QObjects 被移动到 QThreads 后信号不再工作
- QSerialPort readyRead() 信号无法正常工作
- boost信号和插槽在不同的线程中不工作(使用boost::asio::io_service)
- Qt5 多线程:信号仅单向工作
- 将信号从工作线程类连接到控制器类 - QThreads
- 这个餐饮哲学家问题(dpp)的解决方案是如何工作的?互斥体和信号量
- 如何向其他节点发出信号,表明主节点没有更多工作可用
- 将工作线程信号与主窗口插槽 (Qt5) 连接时出错
- 为什么我的工作人员线程未收到此信号
- 默认情况下,从工作线程发出Qt::信号会使主线程上的UI更新?
- 信号处理程序和图书馆工作人员线程
- Qt:信号插槽不工作
- 如果堆分配的对象被销毁并且指针被重新分配,Qt的信号和插槽系统会工作吗?
- 发出信号无法正常工作
- 如何将信号连接到boost :: asio :: io_service在其他线程上发布工作时
- qt qudpsocket:readyread()信号和相应的插槽无法正常工作
- 互斥信号量是如何工作的
- pthread_cond_wait/信号和互斥锁无法按预期工作
- Qt信号槽不工作