PDA

View Full Version : not able to read output from the terminal



jack101
26th March 2012, 13:51
this code was meant to compile a C file and read the errors encountered while compiling a file through gcc in ubuntu.
my problem is that variable result is always empty, even in case of error containing file, result should have "errors" (these are same errors which are displayed in terminal if file is compiled )



QProcess myProcess;
QString program = "gcc";
QStringList arguments;
arguments << fileName;
myProcess.start(program, arguments);
myProcess.waitForFinished();
QByteArray result = myProcess.readAllStandardOutput ();
const QString a (result);
if(!a.isEmpty())
{
QFont font1;
font1.setFamily("Courier");
font1.setFixedPitch(true);
font1.setPointSize(10);
font1.setBold(true);

QTextEdit *errorWindow;
errorWindow = new QTextEdit;
errorWindow->setFont(font1);
errorWindow->setText(a);
errorWindow->show();
}

MrShahi
26th March 2012, 13:55
I think you show use signal slot mechanism to read standard output of process.
like
connect(&myProcess,SIGNAL(readyReadStandardOutput()),this,S LOT(readStandardData());
//readStandardData() is slot from where you can read data of your process.

I hope this will help you..

jack101
26th March 2012, 16:26
I think you show use signal slot mechanism to read standard output of process.
like
connect(&myProcess,SIGNAL(readyReadStandardOutput()),this,S LOT(readStandardData());
//readStandardData() is slot from where you can read data of your process.

I hope this will help you..

no readStandardOutput() is a standard function of QProcess, i didn't used any signal slot mechanism for this part.

wysota
26th March 2012, 17:53
Are you sure errors go to STDOUT and not STDERR?