QThread线程挂起需要一个QWaitCondition对象,并且需要传入一个QMutex对象作为参数,QMutex对象初始化的时候应该是锁定状态,否则将出现异常情况,参考 QT多线程QWaitCondition的问题 https://bbs.csdn.net/topics/380203764。
然后再调用cond.wait()挂起线程。cond.wakeAll()唤醒线程.
代码如下(从工程里扣下来的,可能需要修改一下才能运行):
class MyThread(QThread):
def __init__(self):
super(MyThread, self).__init__()
self.mutex = QMutex()
self.mutex.lock()
self.cond = QWaitCondition()
def wait(self):
self.cond.wait(self.mutex)
def wake(self):
self.cond.wakeAll()
def run(self):
for i in range(10000):
if i>=100:
self.wait()