在冒落線程信號插槽我在主線程一些自定義的信號,我想在我的其他線程發出,但我不知道如何將它們連接起來。有人可以發表一個例子嗎?PyQt4的主線程
例如:
import sys, time
from PyQt4 import QtGui as qt
from PyQt4 import QtCore as qtcore
app = qt.QApplication(sys.argv)
class widget(qt.QWidget):
signal = qtcore.pyqtSignal(str)
def __init__(self, parent=None):
qt.QWidget.__init__(self)
self.signal.connect(self.testfunc)
def appinit(self):
thread = worker()
thread.start()
def testfunc(self, sigstr):
print sigstr
class worker(qtcore.QThread):
def __init__(self):
qtcore.QThread.__init__(self, parent=app)
def run(self):
time.sleep(5)
print "in thread"
self.emit(qtcore.SIGNAL("signal"),"hi from thread")
def main():
w = widget()
w.show()
qtcore.QTimer.singleShot(0, w.appinit)
sys.exit(app.exec_())
main()
信號從未提出。
我忘了提及它們是新風格的信號 – user393899 2012-03-08 09:01:05
您是否使用QThread或python的線程? – Dikei 2012-03-08 09:28:23
我使用的QThread – user393899 2012-03-08 09:41:48