无法打印正确解码的 readAllStandardOutput
can't print readAllStandardOutput correctly decoded
我有这段代码可以将进程的所有输出打印到文本字段中:
data = self.m_process.readAllStandardOutput()
s = str(data)
self.m_ui.b_renderOutput.append(s)
我在输出中得到的是这样的:
b''
b''
b''
b'\r\nStarting "C:\Program Files'
b''
b'\Autodesk\Maya2018\bin\mayabatch.exe"\r\n'
b'Initialized VP2.0 renderer {\r\r\n'
我无法以正确的方式解码和打印它。我知道来自 readAllStandardOutput 的是 QByteArray
如果要转换QByteArray to string, first convert it to bytes using the data() method, and then decode()将其转换为字符串:
data = self.m_process.readAllStandardOutput()
s = data.data().decode() # <---
self.m_ui.b_renderOutput.append(s)
另一种方法是将QByteArray to bytearray and then use decode():
data = self.m_process.readAllStandardOutput()
s = bytearray(data).decode() # <---
self.m_ui.b_renderOutput.append(s)
我有这段代码可以将进程的所有输出打印到文本字段中:
data = self.m_process.readAllStandardOutput()
s = str(data)
self.m_ui.b_renderOutput.append(s)
我在输出中得到的是这样的:
b''
b''
b''
b'\r\nStarting "C:\Program Files'
b''
b'\Autodesk\Maya2018\bin\mayabatch.exe"\r\n'
b'Initialized VP2.0 renderer {\r\r\n'
我无法以正确的方式解码和打印它。我知道来自 readAllStandardOutput 的是 QByteArray
如果要转换QByteArray to string, first convert it to bytes using the data() method, and then decode()将其转换为字符串:
data = self.m_process.readAllStandardOutput()
s = data.data().decode() # <---
self.m_ui.b_renderOutput.append(s)
另一种方法是将QByteArray to bytearray and then use decode():
data = self.m_process.readAllStandardOutput()
s = bytearray(data).decode() # <---
self.m_ui.b_renderOutput.append(s)