将控制台数据从进程输出到 wxwidgets 中的 gui

发布于 2024-11-02 04:14:13 字数 262 浏览 5 评论 0原文

我正在后台运行一个很长的进程。我已经成功地将控制台数据输出到图形用户界面。但问题是,数据只有在进程完成后才会返回。但我需要实时显示数据。即,我需要在每次在控制台上产生一些输出时显示数据。我正在我的 gui 中从一个单独的线程运行该进程。

我的意思是,这就像为 ping 命令构建一个 GUI,在发送每个数据包后(即实时)在控制台上显示输出。我只需要实时将其重定向到图形用户界面。我正在 wxwidgets 中实现 gui。任何帮助将不胜感激。

谢谢你

..Jvc

I'm running a long process in the background. I've managed to output the console data to gui. But the problem is that, the data is returned only after the process is finished. But I need to display the data at realtime. ie, I need to display the data, every time it produces some output on the console. I'm running the process with in my gui from a seperate thread.

I mean, it would be like building a gui for the ping command, where output is displayed on console after each packet is send, ie at realtime. I just need to redirect that to gui, in realtime. I'm implementing the gui in wxwidgets. Any help would be greatly appreciated.

Thanking You..

Jvc

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡水深流 2024-11-09 04:14:13

您希望显示的输出是在与运行 GUI 的进程不同的进程中生成的吗?或者在同一进程的单独线程中?

我问这个问题是因为大多数人在问这个问题时意味着一个单独的线程。既然您已经用“过程”标记了您的问题,我将假设这就是您的意思。

您需要一些进程间通信。有各种各样的技术可以做到这一点。就我个人而言,我总是使用套接字。

wxWidgets有简单、易于使用的套接字类wxSocketClient和wxSocketServer。

后台进程可能没有运行 wxWidgets,因此您需要其他东西。我推荐 boost::asio。我知道它看起来很吓人,但实际上教程代码可以按原样使用。

还有很多话要说,但我可能会偏离主题,因为你的问题中的细节很少。

Is the output you wish to display generated in a separate process from the process running the GUI? Or in a separate thread in the same process?

I ask because most people, when they ask this question, mean a a separate thread. Since you have tagged your question with "process" I will assume that is what you mean.

You need some inter-process communication. There is a bewildering variety of techniques to do this. Personally, I always use sockets.

wxWidgets has simple, easy to use socket classes wxSocketClient and wxSocketServer.

The background process is probably not running wxWidgets, so you will need something else there. I reccomend boost::asio. I know it looks intimidating, but in fact the tutorial code can be used as is.

There is a lot more to be said, but I risk straying away from the point, since there are so few details in your question.

枯寂 2024-11-09 04:14:13

你可以有一个由 wxMutex 保护的输出队列。执行计算的线程写入队列,然后使用 wxQueueEvent 和自定义事件向 GUI 线程发出信号,让它知道该线程不为空​​。 GUI 线程然后读取队列并输出数据。

You can have an output queue protected by a wxMutex. The thread doing the computation writes to the queue, then signals the GUI thread using wxQueueEvent with a custom event to let it know that the thread is not empty. The GUI thread then reads the queue and outputs the data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文