我试图从10个线程中的每一个中绘制10个矩形。使用QT MoveToThread样式它工作正常(使用Signal& Slot) 但是当我尝试使用std :: async时,而不是MoveToThread,只有在程序结束执行后才显示(显示)竞争矩形。直到那时GUI被绞死了。我已经提到了下面程序的代码逻辑。 (发布实际代码需要太长时间)。如何使用Signal&使用std :: async()时的插槽概念?
代码逻辑
1) class Process : Public QObject {
Q_Object
Process_slot {
emit Update_ui_signal //connected to Update_ui_slot of below class
}
Process_method {
emit Update_ui_signal //connected to Update_ui_slot of below class
}
};
2) class UpdateUI : Public QObject {
Q_Object
Update_ui_slot {
update ui
}
};
QT MoveToThread代码:
//here its working as expected
//Real time update happen
Process_object[10];thread_object[10];
Process_object[].movetothread(thread_object[])
connect(call process_slot when thread_object start)
thread_object[].start()
STD ::异步代码:
//here the GUI got hanged and got the expected result after the execution finished
//Real time update not happening
std::future objF[10];
objF[] = std::async(std::launch::async, Process_method)
objF[].get();
STD ::线程代码:
//Behaved as same as the std::async
如果需要“实际代码”/“更多信息”,请告诉我。