问题
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