c++ - 让主线程等到所有其他 Qthread 完成

标签 c++ qthread

有没有办法强制主线程等待,直到从它创建的所有线程都将完成它们的工作,然后才能完成程序。我的意思是:

int main(){
    QthreadClass a; // in cons' a thread is created and running
    QthreadClass b; // same as before

    *** wish to wait till both created thread finished their jobs ***

    return 0;

最佳答案

那么,关于:

a.wait();
b.wait();

或者,您宁愿启动一个事件循环(通常用于 Qt 应用程序),当您的两个线程都结束时(QThread 发出 finished() 和 terminated() 信号)退出。

关于c++ - 让主线程等到所有其他 Qthread 完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15324017/

相关文章:

c++ - QThread:如何使用 protected 静态函数

c++ - 查找二进制二维数组中的唯一行

c++ - 实际上,自定义的 Double 类会比内置的 double 慢得多吗?

multithreading - 从非 UI QThread 修改 QStandardItemModel?

multithreading - 可以从另一个 QThread 安全地发出 Qt 信号吗

Qt,如何立即暂停QThread

python - 向其他QThread发送消息

c++ - 自顶向下递归下降解析 : Relying on tail call optimization

C++:重载2个函数,一个在头文件中,一个不在

c++ - Win32 : Is there a difference between Dr. Watson 的完整/小型转储并编写我自己的?