在 Qt 4.7 中将标准输出通过管道传输到 QLabel
我正在尝试将大学 C++ 代码包装在 Qt 小部件中。
但是,他的程序标准输出必然需要查看。截至目前,我假设我将构建一个 GUI 并打开一个 QProccess 来运行他的程序(然后通过该管道发送命令)。
所以我的问题是无论如何要读取该程序的标准输出并将其显示在 qlabel 或类似的东西中(即我应该研究哪些功能)?
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)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当进程运行时,
QProcess
对象将发出 <一旦标准输出上有可用数据,code>readyReadStandardOutput() 就会发出信号。您可以订阅信号,调用readAllStandardOutput()
< /a> 从连接的插槽并将数据附加(而不是替换)到您的小部件。如果您不需要数据一到达就显示,您可以等到该过程完成,然后一次性读取所有输出。As the process runs, the
QProcess
object will emit thereadyReadStandardOutput()
signal as soon as there are data available on the standard output. You can subscribe to the signal, callreadAllStandardOutput()
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.