pyqt4:线程的串联运行方式

有些时候我们在pyqt中需要线程串行运行,而不是并发运行,用以下方式,这是在网上找的,暂存。

> Hello
> I have something like the foll scenario:
>
> class A(QThread):
>     def __init__(self):
>         QThread.__init__(self)
>     def run(self):
>         # do something
>         pass
> class B:
>      def __init__(self):
>          a = A()
>          a.start()
>          # a.join()               # how do i do this???
>
> Basically i want class B to "wait" till thread in class A has run
> completely. But it seems QThread does not have a ".join" method. How
> do i achieve the above?
>
> Any suggestions would be encouraging!

QThread.wait() should do what you want, i.e.,


 class B:
      def __init__(self):
          a = A()
          a.start()
          a.wait() # blocks until a's run() method has finished.

 

posted @ 2016-11-28 19:57    阅读(660)  评论(0编辑  收藏  举报