我使用QEvent
异步运行流程,在我的流程完成后,我只是设置承诺并尝试使用将来的get函数来获取它。
然而,它不是异步工作,它同步工作。
我可以知道我在做什么错吗?
码
Win::Win(QObject *parent) :
MyCustomWidget(parent)
{
qDebug()<<execute().get();
}
std::future<int> Win::execute()
{
auto promise = std::make_shared<std::promise<int>>();
auto temp = [=]
{
///process
qDebug()<<"done";
promise->set_value(100);
};
QApplication::postEvent(this,new MyCustomEvent(temp));
////QApplication::processEvents() without this line its not working may know the reason
//// But without this line and without future get also its working
return promise->get_future();
}