[Tutor] How to redirect console output to a TextEdit box on a QT Python Gui ?

SM sunithanc at gmail.com
Sun Jun 16 19:15:59 CEST 2013


Hi
I have implemented a GUI using PyQt4/python3, which allows the user to
select a few files as command-line arguments. When I hit "OK" button, my
application runs and the output text is displayed on the terminal where I
run the python script. I would like to redirect this text to a TextEdit
window I have created on the GUI:

self.textEdit = QtGui.QTextEdit(Form)
self.textEdit.setGeometry(QtCore.QRect(10, 300, 421, 141))
self.textEdit.setObjectName(_fromUtf8("textEdit"))

Do you have any suggestions/tips as to how I can accomplish this task?
Using some suggestions online,  I tried creating a QProcess object and
connect the signal to a function which  reads the std output. But I don't
know how to set the arguments to the call "process.start".

self.process = QtCore.QProcess()
QtCore.QObject.connect(self.process, QtCore.SIGNAL("readyReadStdout()"),
self.readOutput)
I know I have to call self.process.start here but am not able to find
examples of how to do it. One example online uses
"self.process.setArguments", but python3/pyQt4 doesn't seem to know about
it. Using the argument directly with process.start is not helping either.

Appreciate any pointers. If there are better ways than what I am trying to
use, appreciate that as well.

Thanks,
-SM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130616/6e0c741c/attachment.html>


More information about the Tutor mailing list