Piping output of a QIODevice to a QTextEdit

社会主义新天地 提交于 2019-12-10 11:57:58

问题


How to I make the output of a QIODevice (QProcess, specifically) go into a QTextEdit in real time?


回答1:


Connect the QProcess::readyRead signal to a slot that then reads from the QProcess using QProcess::readAllStandardOutput and writes the text to the QTextEdit with QTextEdit::append.




回答2:


Write own class!

Header:

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

Source:

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;
}


来源:https://stackoverflow.com/questions/5587504/piping-output-of-a-qiodevice-to-a-qtextedit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!