void ProcessLineMaker::slotReceivedStderr( const QString& s ) { counterErr++; // Flush stdout buffer if (!stdoutbuf.isEmpty()) { emit receivedStdoutLine(stdoutbuf); stdoutbuf = ""; } stderrbuf += s; int pos; while ( (pos = stderrbuf.find('\n')) != -1) { lineErr = stderrbuf.left(pos); stderrbuf.remove(0, pos+1); emit receivedStderrLine(lineErr); } // Do not remove this line! It makes the method thread safe. // Because we can be interrupted whenever more data is available, // this prevents printing the same data twice. lineErr = ""; counterErr--; //The process has benn killed and all the process'outputs sent to be print, //warn the processWidget. if(counterErr == 0 && (isProcessKilled || isWidgetHidden)) emit outputTreatmentOver(); }
ProcessWidget::ProcessWidget(QWidget *parent, const char *name) : QListWidget(parent) { //No selection will be possible setSelectionMode(QAbstractItemView::NoSelection); setFocusPolicy(Qt::NoFocus); QPalette pal = palette(); pal.setColor(QPalette::HighlightedText, pal.color(QPalette::Normal, QPalette::Text)); pal.setColor(QPalette::Highlight, pal.color(QPalette::Normal, QPalette::Mid)); setPalette(pal); setCursor(QCursor(Qt::ArrowCursor)); //Create the process childproc = new QProcess(); procLineMaker = new ProcessLineMaker( childproc ); connect( procLineMaker, SIGNAL(receivedStdoutLine(QString)), this, SLOT(insertStdoutLine(QString))); connect( procLineMaker, SIGNAL(receivedStderrLine(QString)), this, SLOT(insertStderrLine(QString))); connect( procLineMaker, SIGNAL(outputTreatmentOver()), this, SLOT(slotOutputTreatmentOver())); connect(this, SIGNAL(hidden()), procLineMaker, SLOT(slotWidgetHidden())); connect(childproc, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(slotProcessExited(int,QProcess::ExitStatus))) ; connect(this, SIGNAL(finished(int,QProcess::ExitStatus)), procLineMaker, SLOT(slotProcessExited())); }