QRunnable
からメインに信号を送信しようとしていますQObject
が、何らかの理由で受信していません。
これはこれを行う正しい方法ですか?
これが小さなテストケースです:
import sys
from PyQt4.QtGui import QApplication
from PyQt4.QtCore import QThreadPool, QObject, QRunnable, pyqtSignal
class WorkerSignals(QObject):
result = pyqtSignal(int)
class Worker(QRunnable):
def __init__(self, task):
super(Worker, self).__init__()
self.task = task
self.signals = WorkerSignals()
def run(self):
print 'Sending', self.task
self.signals.result.emit(self.task)
class Tasks(QObject):
def __init__(self):
super(Tasks, self).__init__()
self.pool = QThreadPool()
self.pool.setMaxThreadCount(1)
def process_result(self, task):
print 'Receiving', task # This does not run
def start(self):
for task in range(10):
worker = Worker(task)
worker.signals.result.connect(self.process_result)
self.pool.start(worker)
self.pool.waitForDone()
if __name__ == '__main__':
app = QApplication(sys.argv)
stuff = Tasks()
stuff.start()