skumar434
17th March 2009, 15:45
Hi All ,
First of all let me explain what I am tring to achive here
"I am tring to update the output of the Qprocess which runs the perl script to a textEdit"
Which should look like qprocess is updateing it runtime.
Please find some of the main code
#include <QtGui>
#include "testcasefm.h"
testCaseFm::testCaseFm( QWidget * parent ): QWidget( parent ),scriptProcess(NULL)
{
setupUi(this);
counter =0 ;
scriptProcess = new QProcess( this );
scriptProcess->setProcessChannelMode(QProcess::MergedChannels);
label_targetName->setFocus();
testCaseFm::init();
//connect(label_targetName ,SIGNAL(setFocus()),this,SLOT(init()));
connect(pushButton_openScript ,SIGNAL(clicked()),this,SLOT(pB_openScript()));
connect(pushButton_runScript ,SIGNAL(clicked()),this,SLOT(pB_runScript()));
connect(pushButton_stopScript ,SIGNAL(clicked()),this,SLOT(pB_stopScript()));
connect(pushButton_closeTestcasefm ,SIGNAL(clicked()),this,SLOT(pB_close()));
connect(scriptProcess ,SIGNAL(readyReadStandardOutput()),this,SLOT(updat eOutputTextEdit()));
connect(scriptProcess ,SIGNAL(readyReadStandardError()),this,SLOT(update ErrorOutputTextEdit()));
connect(scriptProcess ,SIGNAL(finished(int, QProcess::ExitStatus)),this,SLOT(processFinished(i nt, QProcess::ExitStatus)));
connect(scriptProcess ,SIGNAL(error(QProcess::ProcessError)),this,SLOT(p rocessError(QProcess::ProcessError)));
}
testCaseFm::~testCaseFm()
{
close();
qDebug() << counter;
}
odes
The method which updates the textedit
void testCaseFm::updateOutputTextEdit()
{
// scriptProcess->setReadChannel(QProcess::StandardOutput);
QByteArray newData = scriptProcess->readAllStandardOutput();
QString text = textEdit->toPlainText()
+QString::fromLocal8Bit(newData);
textEdit->append(text);
counter++;
}
void testCaseFm::updateErrorOutputTextEdit()
{
// textEdit->append("----------Stard Error---------");
// scriptProcess->setReadChannel(QProcess::StandardError);
QByteArray newData = scriptProcess->readAllStandardError();
QString text_error = textEdit->toPlainText()
+QString::fromLocal8Bit(newData);
textEdit->append(text_error);
}
The output which I am getting from the Qprocess
/dev/nst
/dev/nst
/dev/nst
/dev/nst
/dev/nst
/dev/nst
/dev/nst
FEWrite_diags_port2000_1
/dev/nst: No such file or directory
/dev/nst: No such file or directory
dd: opening `/root/logs/FEWrite_diags_port2000_1': No such file or directory
The actual out put when I run the script on the linbux box
/dev/nst
FEWrite_diags_port2000_1
/dev/nst: No such file or directory
/dev/nst: No such file or directory
dd: opening `/root/logs/FEWrite_diags_port2000_1': No such file or directory
I suspect the output method is going into loop but I dont know why ...
I would appricate any suggestion ...plz
One more thing i wanted to know is " can I update the textedit which is in main thread
sing new thread ".
First of all let me explain what I am tring to achive here
"I am tring to update the output of the Qprocess which runs the perl script to a textEdit"
Which should look like qprocess is updateing it runtime.
Please find some of the main code
#include <QtGui>
#include "testcasefm.h"
testCaseFm::testCaseFm( QWidget * parent ): QWidget( parent ),scriptProcess(NULL)
{
setupUi(this);
counter =0 ;
scriptProcess = new QProcess( this );
scriptProcess->setProcessChannelMode(QProcess::MergedChannels);
label_targetName->setFocus();
testCaseFm::init();
//connect(label_targetName ,SIGNAL(setFocus()),this,SLOT(init()));
connect(pushButton_openScript ,SIGNAL(clicked()),this,SLOT(pB_openScript()));
connect(pushButton_runScript ,SIGNAL(clicked()),this,SLOT(pB_runScript()));
connect(pushButton_stopScript ,SIGNAL(clicked()),this,SLOT(pB_stopScript()));
connect(pushButton_closeTestcasefm ,SIGNAL(clicked()),this,SLOT(pB_close()));
connect(scriptProcess ,SIGNAL(readyReadStandardOutput()),this,SLOT(updat eOutputTextEdit()));
connect(scriptProcess ,SIGNAL(readyReadStandardError()),this,SLOT(update ErrorOutputTextEdit()));
connect(scriptProcess ,SIGNAL(finished(int, QProcess::ExitStatus)),this,SLOT(processFinished(i nt, QProcess::ExitStatus)));
connect(scriptProcess ,SIGNAL(error(QProcess::ProcessError)),this,SLOT(p rocessError(QProcess::ProcessError)));
}
testCaseFm::~testCaseFm()
{
close();
qDebug() << counter;
}
odes
The method which updates the textedit
void testCaseFm::updateOutputTextEdit()
{
// scriptProcess->setReadChannel(QProcess::StandardOutput);
QByteArray newData = scriptProcess->readAllStandardOutput();
QString text = textEdit->toPlainText()
+QString::fromLocal8Bit(newData);
textEdit->append(text);
counter++;
}
void testCaseFm::updateErrorOutputTextEdit()
{
// textEdit->append("----------Stard Error---------");
// scriptProcess->setReadChannel(QProcess::StandardError);
QByteArray newData = scriptProcess->readAllStandardError();
QString text_error = textEdit->toPlainText()
+QString::fromLocal8Bit(newData);
textEdit->append(text_error);
}
The output which I am getting from the Qprocess
/dev/nst
/dev/nst
/dev/nst
/dev/nst
/dev/nst
/dev/nst
/dev/nst
FEWrite_diags_port2000_1
/dev/nst: No such file or directory
/dev/nst: No such file or directory
dd: opening `/root/logs/FEWrite_diags_port2000_1': No such file or directory
The actual out put when I run the script on the linbux box
/dev/nst
FEWrite_diags_port2000_1
/dev/nst: No such file or directory
/dev/nst: No such file or directory
dd: opening `/root/logs/FEWrite_diags_port2000_1': No such file or directory
I suspect the output method is going into loop but I dont know why ...
I would appricate any suggestion ...plz
One more thing i wanted to know is " can I update the textedit which is in main thread
sing new thread ".