我尝试使用QProcess并将stdout读入由按钮启动的QTextEdit。我如何调整this example来实现这一点?是否必须为QProcess调用单独的类?在
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys
class MyQProcess(QProcess):
def __init__(self):
#Call base class method
QProcess.__init__(self)
#Create an instance variable here (of type QTextEdit)
self.edit = QTextEdit()
self.edit.setWindowTitle("QTextEdit Standard Output Redirection")
self.edit.show()
#Define Slot Here
@pyqtSlot()
def readStdOutput(self):
self.edit.append(QString(self.readAllStandardOutput()))
def main():
app = QApplication(sys.argv)
qProcess = MyQProcess()
qProcess.setProcessChannelMode(QProcess.MergedChannels);
qProcess.start("ldconfig -v")
QObject.connect(qProcess,SIGNAL("readyReadStandardOutput()"),qProcess,SLOT("readStdOutput()"));
return app.exec_()
if __name__ == '__main__':
main()
使用
QPushButton
制作一个按钮。在使用
QPushButton.clicked.connect
绑定事件。在例如:
相关问题 更多 >
编程相关推荐