How display data from an external thread

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
OlivierF
In need of some credit
In need of some credit
Posts: 1
Joined: Mon Jan 30, 2023 3:31 pm

How display data from an external thread

Post by OlivierF »

Hi, I am not a very experienced programmer in c++ and wxWidgets.

I would like to have an example on how wxWidgets could display incomming serial data from a non wxWidgets thread.

I need to have a C++ console application that run several different threads not depending on wxWidgets.
I need to be able to display data to the wxwidgets app in a textbox for this example.
I also need to receive command from wxwidgets to act in my core program (the other threads).
The point of all this is to be able to use any GUI with the core program.

I understand how to create a custom event (I think lol).
But I struggle to queue the event or to use the callafter() function.

Can someone show me a quick set up to do so please?
Dont hesitate if I did not put enough details.

Olivier
User avatar
doublemax
Moderator
Moderator
Posts: 19117
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How display data from an external thread

Post by doublemax »

I think the wxThread documentation properly demonstrates how to use events (the principle remains the same even if you don't use wxThread):
https://docs.wxwidgets.org/trunk/classwx_thread.html

Here's a sample using CallAfter():
minimal.cpp
(8.7 KiB) Downloaded 45 times

In both cases you need an object that derives from wxEvtHandler (usually a wxFrame or wxPanel). Either to send the event to it, or to invoke its CallAfter method.
Use the source, Luke!
Post Reply