PDA

View Full Version : Cannot read QProcess output for some applications



yagabey
5th July 2015, 03:04
Hi,
I am trying to read console output of a qt console app from a qt gui app.


void MainWindow::on_pushButton_clicked()
{
proc= new QProcess(this);
connect(proc,SIGNAL(readyReadStandardOutput()),thi s,SLOT(readProcessOutput()));
proc->setProcessChannelMode(QProcess::MergedChannels);
proc->start("C:\\Users\\yg\\Documents\\processtest\\debug\\depl oyFiles.bat");
}
void MainWindow::readProcessOutput()
{
ui->textEdit->append(proc->readAllStandardOutput());
}

I can read the output for "deployFiles.bat" app. But when i change the file to :

proc->start("C:\\Users\\yg\\Documents\\processtest\\debug\\Driv erModbus.exe");


Nothing comes to standartoutput.
DriverModbus is a qt console app that uses qDebug() s to print data on its console.

https://dl.dropboxusercontent.com/u/3790845/DriverModbus.rar

What maybe the problem?

Thanks in advance...

jefftee
5th July 2015, 05:15
qDebug write to stderr not stdout.

yagabey
5th July 2015, 09:03
Hi Jefftee,

I think "proc->setProcessChannelMode(QProcess::MergedChannels)" directs all output to stdout. So that shouldnt be a problem. And i already tried replacing "readyReadStandardOutput to readyReadStandardOutput" and "readAllStandardOutput toreadAllStandardError". Result not changing..

And a few additional information ; i am sure the process is running. When i check its state i see it "running". And When i exit the application i see


QProcess: Destroyed while process ("C:\Users\yg\Documents\processtest\debug\DriverModb us.exe") is still running

output on the console

yagabey
5th July 2015, 11:21
Ok, i discovered one more thing. I can read output when i use:


QTextStream stream(stderr);
stream << out;

or


QTextStream stream(stdout);
stream << out;

But cannot read output from:


qDebug() << out ;

Strange? No idea?

anda_skoa
5th July 2015, 12:41
Does the application output appears on a terminal when your run it normally?

Cheers,
_

yagabey
5th July 2015, 13:33
Yes, it does..

anda_skoa
5th July 2015, 14:29
One thing I could imagine is that the logging framework detects if there is a controlling terminal and output to it if there is.
And if there is not it logs to some system logging factility

Cheers,
_

yagabey
6th July 2015, 09:57
Not a solution ;but for now i think i need to use "stdout" ...

anda_skoa
6th July 2015, 11:26
Yes, using the correct streams explicitly is a better solution anyway.
More control of which stream something is written to and more control on how the data is formatted, etc.

Cheers,
_