管道标准输出到Qt 4.7中的QLabel [英] piping standard output into QLabel in Qt 4.7

查看:280
本文介绍了管道标准输出到Qt 4.7中的QLabel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



但是,他的程序std输出必须要被查看。到现在为止,我假设我将构建一个GUI并打开一个QProccess,将运行他的程序(然后通过该管道发送命令)。



所以我的问题是有无论如何读取该程序的标准输出,并显示在一个qlabel或类似的东西(即我应该查看什么功能)?

解决方案

在进程运行时, QProcess href =http://doc.qt.nokia.com/4.7/qprocess.html#readyReadStandardError =nofollow> readyReadStandardOutput() signal一旦有标准输出上的数据可用。您可以订阅信号,请致电 readAllStandardOutput() ,并将数据附加(不替换)到您的窗口小部件。如果您不需要在数据到达时立即显示,您只需等待过程完成,然后一次性读取所有输出。


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)?

解决方案

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.

这篇关于管道标准输出到Qt 4.7中的QLabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆