PDA

View Full Version : help QProcess



totosugito
30th January 2008, 09:58
Dear,
I want to use QProcess to solve my problem.
in my form, I have :
1. lineedit to input command cell
2. pushbutton to process command
3. textedit for output process

in my script i want to insert text :
txtOutput->append("operation ending");
after qprocess ending, but in my script, this text appear in top of output not in bottom textoutput.
this script execute before process ending.
how to make this script execute after qprocess ending?

this is complete my scripts :


#include "qtwiggle.h"

qtwiggle::qtwiggle(QWidget* parent)
: QMainWindow(parent)
{
setupUi(this);
setWindowTitle(tr("Tape Utilities"));
}

void qtwiggle::on_btnRun_clicked()
{
QString perintah=txtInput->text();
proc= new QProcess();
proc->start("/bin/bash", QStringList() << "-c" << perintah);
connect(proc, SIGNAL(readyReadStandardOutput()),this, SLOT(rightc()) );
connect(proc, SIGNAL(readyReadStandardError()), this, SLOT(wrongc()) );
txtOutput->append("operation ending");
}

void qtwiggle::rightc()
{
QByteArray databaca = proc->readAllStandardOutput();
txtOutput->append(databaca);
}

void qtwiggle::wrongc()
{
QByteArray databaca = proc->readAllStandardError();
txtOutput->append(databaca);
}

thank you

croftj
30th January 2008, 14:28
My solution is clunky and there are probably better ways to do it. The upside is that it is simple and lets me colorize and format the strings I put out. I have a function which writes the text out for me:



void appendStatusWindow(QTextEdit *wdt, QString s)
{
QString str = wdt->toHtml();
if ( str.size() > 0 )
{
str.replace("<html>", "");
str.replace("</html>", "");
}
str += s;
str = "<html>\n" + str + "</html>\n";
wdt->clear();
wdt->append(str);
wdt->ensureCursorVisible();
};

totosugito
31st January 2008, 07:50
thank for your answer.
but my complex problem is if I have two process. I want to run process 2 after process 1 ending. so I must know when process 1 ending.
how to know that ?
my problem above is a simple problem

thanks you

CrackedMind
31st January 2008, 14:42
waitForFinished() and state() methods can help you...