QFutureWatcher没有调用已连接的插槽
QFutureWatcher not calling connected slot
我有以下代码实现QtConcurrent::run()
与QFutureWatcher
启动运行shell进程的fetch()
函数。完成后,我想调用writeDesc
函数,但它从未被调用。
void MyClass::on_fetchButton_clicked()
{
QFuture<void> fetcher;
QFutureWatcher<void> watcher;
connect(&watcher, SIGNAL(finished()), this, SLOT(writeDesc()));
fetcher = QtConcurrent::run(this, &MyClass::fetch);
watcher.setFuture(fetcher);
}
void MyClass::fetch()
{
[...]
qDebug()<<"Thread done";
}
void MyClass::writeDesc()
{
qDebug()<<"Slot called";
[...]
}
fetch()
工作正常,但程序只显示调试消息Thread done
而不显示Slot called
。为什么不叫writeDesc
?
问题是在离开MyClass::on_fetchButton_clicked()
方法时监视对象被销毁。一个被破坏的物体不能发出什么东西。尝试在类的构造函数中分配和连接监视器。别忘了在析构函数中销毁。
相关文章:
- 升压信号2将插槽传递到成员功能以断开连接
- 如何在qt中将信号和插槽与另一个对象连接 --解决了
- QObject::连接无法将信号连接到*this*对象的插槽
- Qt5:连接:如果插槽的参数少于信号,如何使用"连接"
- 使用std::bind将Qt信号连接到插槽
- 使用信号和插槽连接多个 UI 对象
- 如果代码中没有连接任何插槽,是否有理由发出Qt信号?
- 连接来自 C++98 接口的 Qt 插槽和信号,无需 Qt、STL 或 Boost
- 连接信号(Qstring)白色插槽(字符串)的2个不同类别
- 文档在哪里说明如果参数不是从末端删除参数,则无法从QT信号插槽连接中删除参数?
- 连接 -> 窗口上没有这样的插槽
- 如何将信号连接到类的所有实例的插槽
- 通过排队的QT信号插槽连接发送QSHAREDPOINTERS的QVECTOR
- Qt转发插槽/连接插槽到插槽?
- 信号和插槽的连接(有关QListView)-QT
- 我可以交换QObject儿童保持信号和连接的插槽吗?
- Qt按钮无法连接插槽
- 如何使用C 插槽连接QML信号
- qnetworkAccessManager一个实例并连接插槽
- 在Qt中连接插槽