我想在 PyQt5 中排队 QProcess 或者只是阻塞,同时仍然使用 readAll() 读取标准输出。相当于 subprocess.call 而不是 subprocess.Pop。当使用 waitForFinished() 时,带有 readAll() 的 stdout 将在进程结束时立即出现,而不是在处理过程中流出。
示例脚本:
from PIL import Image
import numpy as np
import sys
from PyQt5 import QtGui,QtCore, QtWidgets
class gui(QtWidgets.QMainWindow):
def __init__(self):
super(gui, self).__init__()
self.initUI()
def dataReady(self):
cursor = self.output.textCursor()
cursor.movePosition(cursor.End)
cursor.insertText(str(self.process.readAll(), "utf-8"))
self.output.ensureCursorVisible()
def callProgram(self):
# run the process
# `start` takes the exec and a list of argument
filepath = 'path\image.tif'
self.process.start('some_command filepath'])
# This will output a file image.tif specified by filepath:
# …Run Code Online (Sandbox Code Playgroud)