【发布时间】:2015-08-30 17:36:58
【问题描述】:
我尝试按照this question 中列出的解决方案进行操作,但是一旦应该发出信号,似乎什么都没有发生。
这不是全部代码,但应该足以证明我正在尝试做的事情:
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 永远不会被调用。对不起,如果这是微不足道的,但我似乎无法让它工作,谢谢! :)
【问题讨论】:
标签: multithreading python-3.x pyqt5