PyQT和QThread遇到了一些问题。 当在QThread run()中使用来自另一个模块的方法时,我无法从中获取值。 我怎么能得到它们?
from PyQt4 import QtCore, QtGui
import sys
class MainWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.initAnotherThread()
self.setFixedSize(640, 360)
self.setWindowTitle('Window')
self.logText = QtGui.QTextEdit(self)
self.logText.setReadOnly(True)
self.logText.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.logText.resize(460, 330)
self.clickButton = QtGui.QPushButton('Click Button', self)
self.clickButton.setFocusPolicy(QtCore.Qt.NoFocus)
self.clickButton.setGeometry(470, 50, 160, 35)
self.connect(self.clickButton, QtCore.SIGNAL('clicked()'), self.onButtonClick)
def initAnotherThread(self):
self.updaterThread = anotherThread(self)
def onButtonClick(self):
self.logText.clear()
self.updaterThread.start()
class anotherThread(QtCore.QThread):
def __init__(self, mw):
super(anotherThread, self).__init__(mw)
self.mw = mw
def run(self):
print "Another thread started"
AnotherModule.anotherMethod()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
main = MainWindow()
main.show()
sys.exit(app.exec_())
在AnotherModule中我有下一个:
anotherMethod():
x=0
while x<100:
x+=1
如何从AnotherModule获取x值?