Hi

First of all I want to thank everyone in this forum who helped me to understand PySide.

I have a question about QtCore.QProcess:
Here how my program works: I have button (QtGui.QPushButton) when it gets clicked, my program should call my C compiler (GCC) and compile the source code. This works perfectly when I had no GUI (Command Line) using subprocess.

Now I'm trying to use QProcess to do a same thing. My MainWindow class has one instance of QProcess and once instance of QtGui.QTextEdit

on __init__

self.process = QtCore.QProcess(self)
self.textEdit = QTextEdit(self)
self.textEdit.move(x, y)

and more

now my button (Which is not in the above code), called btn_run has an event the when it gets clicked it start the process

args = ["-o", "myfile", "myfile.c"]
self.process.start("gcc", args)

Now what I want to do is to get the outputs that generated by gcc on STDOUT, STDERR from QProcess to show them in QTextEdit line by line (as gcc puts something on STOUT or STDERR I show that on my QTextEdit)

Here are two problems that I have, First my UI freezes, meaning that I cant press anything else with my UI and I get no output on my QTextEdit. (I used readLine() function which is from QIODevice, which is a parent class of QProcess).

Any suggestion?

Thanks again.


--
Mark

vegaseat, Thanks for your reply

Now I have everything working. Here how I did it:

__NOTE__: class MyWindow(QWidget):

In __init__

self.proc = QtCore.QProcess(self)
self.te   = QTextEdit(self)
self.btn  = QPushButton("Execute", self)
self.btn.clicked.connect(self.__event_btn)

Now I have this:

def __event_btn(self):
    w_dir = "" # This set to my working directory where my C files are
    args  = ["-o", "MyFile", "MyFile.c"]
    cmd   = "gcc"

    self.proc.setWorkingDirectory(dir)
    self.proc.readyReadStandardOutput.connect(self.__read)
    self.proc.closeWriteChannel()
    self.proc.setReadChannel(QtCore.QProcess.StanfardOutput())
    self.proc.start(cmd, args)

def __read(self):
    self.te.setText(self.proc.readAllStandardOutput)

The code above won't show anything until the process done executing.

Now my question is, is there any way that I can capture the output from gcc and show them in TextEdit by not waiting for the process to be finished? (The way that cmd.exe or teminal does. They show the output as the program runs)

Thanks

--
Mark

This article has been dead for over six months. Start a new discussion instead.