PDA

View Full Version : QProcess and Qtextedit problem



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 ".

faldzip
17th March 2009, 18:24
1. First of all use CODE tags instead of QUOTE - it's difficult to get through your pasted code now...
2. What I can see is that when you want to show next part of output you are appending existing text plus new text. So it looks like this:
You have this in your textEdit


some text

and you get from the output string "some different text", Now you are getting the old "some text" adding "some different text" to it and than appending (adding to the end) it to textEdit. The result is:


some text
some text
some different text

instead of:


some text
some different text

Append means "add to the end" so you can just append new portion of text without copying existing text one more time.