将QIODevice的输出管道输出到QTextEdit

时间:2011-04-07 20:52:28

标签: qt qt4 qtextedit qprocess

如何让QIODeviceQProcess,特别是)的输出实时进入QTextEdit

2 个答案:

答案 0 :(得分:1)

QProcess::readyRead信号连接到一个插槽,然后使用QProcess::readAllStandardOutput从QProcess读取,并使用QTextEdit::append将文本写入QTextEdit。

答案 1 :(得分:0)

写自己的班级!

部首:

class MyProcess : public QProcess
{
  Q_OBJECT
...
protected:
  virtual qint64 readData( char * data, qint64 maxlen );
...
};

来源:

qint64 MyProcess::readData( char * data, qint64 maxlen )
{
  qint64 return_value = QProcess::readData(data,maxlen);
  QString str(QByteArray(data,return_value));
  // write out to QTextEdit
  return return_value;
}