piping standard output into QLabel in Qt 4.7

2019-08-20 05:51发布

I am trying to wrap a colleges c++ code in a Qt widget.

However, his programs std output necessarily needs to be viewed. As of now I am assuming I will build a GUI and open a QProccess that will run his program (then send commands over that pipe).

So my question is there anyway to read the standard output of that program and display it in a qlabel or something similar (i.e. what functions should I be looking into)?

1条回答
The star\"
2楼-- · 2019-08-20 06:21

As the process runs, the QProcess object will emit the readyReadStandardOutput() signal as soon as there are data available on the standard output. You can subscribe to the signal, call readAllStandardOutput() from the connected slot and append (not replace) the data to your widget. If you don't need the data to be displayed as soon as it arrives, you can just wait until the process finishes and then read all the output as once.

查看更多
登录 后发表回答