我在程序的“主”线程中创建了一个 QTextEdit 组件,然后我启动另一个线程,它将每 x 秒更新一次此 QTextEdit,但随后出现此错误:
QObject: Cannot create children for a parent that is in a different thread.
这就是我这样做的方式:
def initGui():
#some gui components
global txt_list
txt_list = QtGui.QTextEdit(w)
txt_list.resize(580,400)
txt_list.move(50, 50)
txt_list.setReadOnly(1)
txt_list.setFont(font_consolas)
#more gui components
def update_list():
t_monitor = threading.Thread(target=monitor_vector)
t_monitor.daemon = True
t_monitor.setName('monitor')
t_monitor.start()
def monitor_vector():
#retrieve info...
lock = threading.Lock
lock = True
txt_list.clear() #clear list, to set the new one
txt_list.setText('updated list')
lock = False
最后两行代码给了我上面提到的错误。有人可以告诉我如何处理这个问题吗?
谢谢!