我是 PyQt 编码的新手。我正在尝试从父进程启动子进程(GUI)。在这个我使用等待条件和互斥体来理解它的功能。这是我的代码:
import sys
from PyQt4 import QtGui, QtCore
waitCondition = QtCore.QWaitCondition()
mutex = QtCore.QMutex()
class Child(QtGui.QWidget):
def __init__(self,ABC=None):
super(Child, self).__init__()
def startUI(self):
self.text = QtGui.QLineEdit()
self.text.returnPressed.connect(self.wakeup)
def wakeup(self):
waitCondition.wakeAll()
class Parent(QtGui.QMainWindow):
def __init__(self, parent=None):
super(Parent, self).__init__()
val = 3
abc = Child(val)
abc.startUI()
mutex.lock()
waitCondition.wait(mutex)
mutex.unlock()
print ("Mutex unlocked")
def main():
app = QtGui.QApplication(sys.argv)
aa = Parent()
aa.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
如果我执行此代码,它不会启动子 GUI,就好像我在 Parent 类中取消注释 waitCondition.wait(mutex) 并运行它,GUI 会显示出来。
有人可以帮我找出我在这里犯的错误吗?