Multithreading 未发出来自QThread的信号
我试着遵循中列出的解决方案,但一旦信号发出,似乎什么都不会发生 这并不是全部代码,但它应该足以演示我要做的事情:Multithreading 未发出来自QThread的信号,multithreading,python-3.x,pyqt5,Multithreading,Python 3.x,Pyqt5,我试着遵循中列出的解决方案,但一旦信号发出,似乎什么都不会发生 这并不是全部代码,但它应该足以演示我要做的事情: class StartQT5(QMainWindow): def __init__(self): super().__init__() [...] self.getFileProperties(path, batch) def getFileProperties(self, path, batch):
class StartQT5(QMainWindow):
def __init__(self):
super().__init__()
[...]
self.getFileProperties(path, batch)
def getFileProperties(self, path, batch):
self.thread = QThread()
self.w = probeThread(self)
self.w.moveToThread(self.thread)
self.w.finished[dict].connect(self.setProbeOutput)
self.thread.started.connect(self.w.run)
self.thread.start()
@pyqtSlot(dict)
def setProbeOutput(self, data):
print("gotOutput")
self.probeOutput = data
print(data)
class probeThread(QObject):
finished = pyqtSignal(dict)
def __init__(self, parent):
super().__init__()
self.parent = parent
self.output = {}
def run(self):
self.output = json.loads(subprocess.check_output('%s -v 0 -print_format json -show_format -show_streams -count_frames "%s"' % (self.parent.ffprobePath, self.parent.file)).decode("utf-8"))
print("finished")
self.finished.emit(self.output)
线程运行正常,但从未调用setProbeOutput。抱歉,如果这是一件小事,但我似乎无法让它工作,谢谢!: 简单地做一下怎么样:
self.w.finished.connect(self.setProbeOutput)
定义新信号并将其附加到插槽时,已经在信号和插槽声明中声明了参数类型