PDA

View Full Version : Real time display of QProcess output in a textBrowser



Tanny007
12th April 2012, 01:40
Hello,
I am a newbie in qt development and i want to transfer the output of QProcess to a textBrowser in real time. I started by executing a simple echo command,but the output of the program is not getting displayed.
What am i doing wrong????


QProcess p;
p.start("echo", QStringList() << "hye");
p.waitForStarted();
QByteArray byteArray = p.readAllStandardOutput();
QStringList strLines = QString(byteArray).split("\n");
QString line= p.readAllStandardOutput();
if(p.state()==QProcess::NotRunning)
ui->textBrowser->append("not running");
ui->textBrowser->append(line);
p.waitForFinished();

Jonny174
12th April 2012, 07:03
Try this code:


QProcess *p = new QProcess( this );

if (p)
{
p->setEnvironment( QProcess::systemEnvironment() );
p->setProcessChannelMode( QProcess::MergedChannels );

p->start( "cmd.exe", QStringList() << "echo" << "hye" );
p->waitForStarted();

connect( p, SIGNAL(readyReadStandardOutput()), this, SLOT(ReadOut()) );
connect( p, SIGNAL(readyReadStandardError()), this, SLOT(ReadErr()) );
}

And in slots ReadOut() and ReadErr():


QProcess *p = dynamic_cast<QProcess *>( sender() );

if (p)
ui->textBrowser->append( p->readAllStandardOutput() ); // p->readAllStandardError()

Abhijeet Kumar
17th December 2015, 04:30
Thanks for the solution...was looking for this.