piping standard output into QLabel in Qt 4.7

懵懂的女人 提交于 2019-12-11 14:44:34

问题


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:


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.



来源:https://stackoverflow.com/questions/4710839/piping-standard-output-into-qlabel-in-qt-4-7

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