coding utf-8 import sys from PyQt4 QtCore import QObject QCoreApplicat

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#-*- coding: utf-8 -*-
import sys
from PyQt4.QtCore import QObject, QCoreApplication, QThread, pyqtSignal, pyqtSlot
class Worker(QObject):
finished = pyqtSignal()
def __init__(self, a):
super(Worker, self).__init__()
self.m_a = a
@pyqtSlot()
def boo(self):
print self.m_a
self.finished.emit()
def connectAll(thread, worker):
worker.finished.connect(thread.quit)
thread.started.connect(worker.boo)
thread.finished.connect(app.exit)
app = QCoreApplication(sys.argv)
thread = QThread()
worker = Worker("Hello, World!")
worker.moveToThread(thread)
connectAll(thread, worker)
thread.start()
sys.exit(app.exec_())