class SSHThread(QThread):
def __init__(self, hostname = '', renderList = [], tabLabelText = 'L0001', parent = None):
""" constructor"""
...omit...
#a new custom signal to set string to textEdit
self.editSignal = pyqtSignal(QString, QString)
...omit...
def run(self):
""" emit the new signal"""
... omit ...
self.emit(SIGNAL('editSignal(QString, QString)'), QString("param1"), QString("param2"))
... omit ...
...... omit ......
def executeBtn(self):
""" connect the new signal and a slot function"""
QObject.connect(self.sshThread, SIGNAL('editSignal(QString, QString)'), self.on_textEdit_update)
... omit ...
def on_textEdit_update(self, param1, param2):
""" the slot function"""
... omit ...
================================================
20151223补充一个完整例子,来源:
http://stackoverflow.com/questions/3891465/how-to-connect-pyqtsignal-between-classes-in-pyqtfrom PyQt4 import QtCoreclass Pot(QtCore.QObject): temperatureRaisedSignal = QtCore.pyqtSignal() def __init__(self, parent=None): QtCore.QObject.__init__(self) self.temperature = 1 def Boil(self): self.temperatureRaisedSignal.emit() self.temperature += 1class Thermometer(): def __init__(self, pot): self.pot = pot self.pot.temperatureRaisedSignal.connect(self.temperatureWarning) def StartMeasure(self): self.pot.Boil() def temperatureWarning(self): print("Too high temperature!")if __name__ == '__main__': pot = Pot() th = Thermometer(pot) th.StartMeasure()
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。