我有以下代码,它实现QtConcurrent::run()
了QFutureWatcher
启动fetch()
运行 shell 进程的函数。完成后,我想调用该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
叫?