【发布时间】:2014-08-17 12:05:55
【问题描述】:
我注意到有很多用户,包括我自己,都不太了解 Qt 中信号和槽的概念。我希望对以下内容有所澄清:
#I have a function that runs as soon as the GUI is built, this takes the information from
#a list and puts it into a string which is then uploaded to a texbox. At the bottom of this
#loop, I want it to call a function in the parent thread via signals and slots, as
#recommended by other users.
class MainWindow(QtGui.QMainWindow):
#all the code needed to build the GUI
thread_mythread = threading.Thread(target = self.updateText, args = ())
thread_mythread.start()
def clearText(self):
self.TextEdit.clear()
def updateText(self):
self.trigger.connect(self.clearText)
while True:
self.trigger.emit()
NewString = list.pop(0)
#I think I may have to use append, as setText() is not safe outside of the parent thread
self.TextEdit.append(NewString)
虽然可能非常不正确,但我尝试使用信号。这是正确的方法吗?我也得到一个错误,说主窗口对象没有属性“触发器”,这是为什么呢?
谢谢。
【问题讨论】:
标签: python qt pyqt pyqt4 signals-slots