PyQt4アプリケーションでワーカースレッドを適切にセットアップしようとしていますが、何らかの理由で、スレッドからの開始信号がワーカーに伝達されていません。
syncThread = QtCore.QThread()
self._syncThread = syncThread
worker = SyncWorker(self.async_sync)
worker.moveToThread(syncThread)
syncThread.started.connect(self.progress.show) #This dialog appears!
syncThread.started.connect(worker.work) # This seems to be a no-op
worker.finished.connect(syncThread.quit)
worker.finished.connect(worker.deleteLater)
syncThread.finished.connect(worker.deleteLater)
syncThread.finished.connect(syncThread.deleteLater)
syncThread.start()
class SyncWorker(QtCore.QObject):
# Emitted whenever done
finished = QtCore.pyqtSignal()
def __init__(self, delegate):
QtCore.QObject.__init__(self)
@QtCore.pyqtSlot()
def work(self):
print("Worker gonna work") #This never prints!
self.finished.emit()
何か案は?
ありがとうございました!
更新: GaryHughesのようにworker->self.workerの名前を変更した後、クラッシュする前に新しいエラーが発生します
QObject::setParent: Cannot set parent, new parent is in a different thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
python: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.
Segmentation fault
アップデート#2気にしないでください!私の労働者はGUIコードを呼び出していましたが、それが新しいエラーの原因でした。self.workerを使用する元の修正は正しいです。