如何将Python控制台输出重定向到QTextBox [英] How to Redirect a Python Console output to a QTextBox
问题描述
我正在开发一个用于重新编译Linux内核的GUI。为此,我需要从Python实现4-5个Linux命令。我使用Qt作为GUI设计器。我已经成功地实现了命令使用 os.system()
调用。但输出在控制台获得。真正的问题是命令的输出是一个需要几乎20-25分钟连续打印的列表。我们如何可以将此控制台输出传输到Qt中设计的文本框。任何人都可以帮助我实现 setSource()
操作在Qt使用源作为现场控制台输出。
self.process = QProcess()
self.connect(self.process,SIGNAL(readyReadStdout()),self.readOutput )
self.connect(self.process,SIGNAL(readyReadStderr()),self.readErrors)
tarsourcepath =sudo tar xvpf+ self.path1
self.process.setArguments (QStringList.split(,tarsourcepath))
self.process.start()
def readOutput(self):
self.textBrowser2.append(QString(self.process.readStdout()))
如果self.process.isRunning()== False:
self.textBrowser2.append(\\\
Completed成功)
def readErrors(self):
self.textBrowser2.append(error:+ QString(self.process。 readLineStderr()))
这对我来说很好。谢谢大家。
I'm working on developing a GUI for the recompilation of Linux kernel. For this I need to implement 4-5 Linux commands from Python. I use Qt as GUI designer. I have successfully implemented the commands using os.system()
call. But the output is obtained at the console. The real problem is the output of command is a listing that takes almost 20-25 min continuous printing. How we can transfer this console output to a text box designed in Qt. Can any one help me to implement the setSource()
operation in Qt using source as the live console outputs.
self.process = QProcess()
self.connect(self.process, SIGNAL("readyReadStdout()"), self.readOutput)
self.connect(self.process, SIGNAL("readyReadStderr()"), self.readErrors)
tarsourcepath="sudo tar xvpf "+ self.path1
self.process.setArguments(QStringList.split(" ",tarsourcepath))
self.process.start()
def readOutput(self):
self.textBrowser2.append(QString(self.process.readStdout()))
if self.process.isRunning()==False:
self.textBrowser2.append("\n Completed Successfully")
def readErrors(self):
self.textBrowser2.append("error: " + QString(self.process.readLineStderr()))
This did the work quite good for me. thank you all.
这篇关于如何将Python控制台输出重定向到QTextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!