使主线程等待所有其他Qthread完成 [英] Making the main thread wait till all other Qthread finished

查看:1503
本文介绍了使主线程等待所有其他Qthread完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是有办法强制主线程等待,直到所有线程创建它,将完成他们的工作,在完成程序之前。我的意思是:

is there a way to force the main thread to wait until all threads created from it, will finish their job, before finishing the program. I mean:

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 emit finished()和terminated()信号)。

Or, you would rather start an event loop (as usually for Qt applications) that you quit when both of your threads end (QThread emits finished() and terminated() signals).

这篇关于使主线程等待所有其他Qthread完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆