How to display the output of a process in a TextEdit widget in real time?
Hi,
I have an application that when run from shell, gives many messages, variable and their data as output in the same shell.
Now, i am running that application with the help of QProcess and i want the resulting ouput to display in my Text Edit widget of my GUI in real time....i.e. as the appication is producing output, it should be appearing in TextEdit concurrently.
I browse the google for the problem and found that people are using readLineStdout() which seems like not a slot provided by QProcess but they are using it as if it is.
Re: How to display the output of a process in a TextEdit widget in real time?
all what you need it's to use QProcess::readyReadStandardOutput/QProcess::readyReadStandardError signals and create slots for these signals, then in these slots you should call QProcess::readAllStandardOutput/QProcess::readAllStandardError and add results in a text edit.
Re: How to display the output of a process in a TextEdit widget in real time?
hmmm..right. I used following code but doesn't display anything in my TextEdit.
Code:
...
QObject::connect(myProcess,
SIGNAL(readyReadStdError
()),
this,
SLOT(updateError
(myProcess
)));
QObject::connect(myProcess,
SIGNAL(readyReadStdOutput
()),
this,
SLOT(updateText
(myProcess
)));
myProcess->start(program);
Definition of updateError and updateText:
Code:
void MainWindow
::updateError(QProcess *myProcess
) {
QByteArray data
= myProcess
->readAllStandardError
();
textEdit_verboseOutput
->append
(QString(data
));
}
void MainWindow
::updateText(QProcess *myProcess
) {
QByteArray data
= myProcess
->readAllStandardOutput
();
textEdit_verboseOutput
->append
(QString(data
));
}
Re: How to display the output of a process in a TextEdit widget in real time?
sigh, you code won't work.
try this
Code:
connect(myProcess, SIGNAL(readyReadStdError()), this, SLOT(updateError()));
connect(myProcess, SIGNAL(readyReadStdOutput()), this, SLOT(updateText()));
myProcess->start(program);
...
void MainWindow::updateError()
{
QByteArray data
= myProcess
->readAllStandardError
();
textEdit_verboseOutput
->append
(QString(data
));
}
void MainWindow::updateText()
{
QByteArray data
= myProcess
->readAllStandardOutput
();
textEdit_verboseOutput
->append
(QString(data
));
}
BUT, myProcess must be a class member of MainWindow or you can cast QObject::sender to QProcess.
PS, you should read more about Signal&Slot mechanism.
Re: How to display the output of a process in a TextEdit widget in real time?
Still not working. The process is however running fine but TextEdit widget remains empty.
My MainWindow class
Quote:
class MainWindow : public QMainWindow, private Ui::MainWindow
{
Q_OBJECT
public:
QProcess *myProcess;
MainWindow(QMainWindow *parent = 0);
private slots:
void updateError();
void updateText();
};
MainWindow.cpp
Code:
void MainWindow::On_pushButton_startAnalysis_Click()
{
connect(myProcess, SIGNAL(readyReadStdError()), this, SLOT(updateError()));
connect(myProcess, SIGNAL(readyReadStdOutput()), this, SLOT(updateText()));
myProcess->start(program);
}
void MainWindow::updateError()
{
QByteArray data
= myProcess
->readAllStandardError
();
textEdit_verboseOutput
->append
(QString(data
));
}
void MainWindow::updateText()
{
QByteArray data
= myProcess
->readAllStandardOutput
();
textEdit_verboseOutput
->append
(QString(data
));
}
Is some error still hiding there from my egle eyes? :mad:
Re: How to display the output of a process in a TextEdit widget in real time?
what do you see in console when this code works?
Code:
void MainWindow::On_pushButton_startAnalysis_Click()
{
qDebug() << connect(myProcess, SIGNAL(readyReadStdError()), this, SLOT(updateError()));
qDebug() << connect(myProcess, SIGNAL(readyReadStdOutput()), this, SLOT(updateText()));
myProcess->start(program);
}
void MainWindow::updateError()
{
QByteArray data
= myProcess
->readAllStandardError
();
qDebug() << data;
textEdit_verboseOutput
->append
(QString(data
));
}
void MainWindow::updateText()
{
QByteArray data
= myProcess
->readAllStandardOutput
();
qDebug() << data;
textEdit_verboseOutput
->append
(QString(data
));
}
Re: How to display the output of a process in a TextEdit widget in real time?
Oh its giving following error
Code:
Object
::connect: No such
signal QProcess::readyReadStdError()Object::connect: (receiver name: 'MainWindow')
Object
::connect: No such
signal QProcess::readyReadStdOutput()Object::connect: (receiver name: 'MainWindow')
But this error should also have appeared in the texEdit_verboseOutput.
I said the program is working fine because i was actually generating an xml file with my 'memviz' application which is generated finely. Sorry din check the console earlier.
Re: How to display the output of a process in a TextEdit widget in real time?
Any idea about this error? Isn't it weird QProcess::readyReadStdError() is a signal provided by QProcess as i see it in Qt Assistant but still i am getting 'no such signal error'.
Re: How to display the output of a process in a TextEdit widget in real time?
Re: How to display the output of a process in a TextEdit widget in real time?
set the
void QProcess::setProcessChannelMode ( ProcessChannelMode mode )
to QProcess::MergedChannels
Re: How to display the output of a process in a TextEdit widget in real time?
Ah...stupid me.
Thanks. It's working now.