wxWidgets and a USB HID device Topic is solved

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
Pier Simon Tilma
Earned a small fee
Earned a small fee
Posts: 11
Joined: Tue Mar 10, 2020 4:52 pm

wxWidgets and a USB HID device

Post by Pier Simon Tilma » Thu Sep 10, 2020 6:56 pm

Anjum, 10-09-2020

Hello everybody,

The case :
A USB HID device is connected and recognised (checked with USBVIEW)
Opening the device and communicating by means of control report work fine
from my application.

In this application also a wxThread is running in which I call
hid_read (library HIDAPI) on a regular basis. If that read is successfull
an Interupt In report has been received from the connected USB HID device. Info
from this report will be displayed in one or more windows (e.g. a wxTextCtrl in a wxFrame).
These windows have an associated pointer which is NULL (window not existing)
or not NULL (window has been created). In above wxThread the pointers
to wxFrames are checked and if not NULL info is written.

The problem :
As soon as a wxFrame for displaying Interupt In reports is created,
the application crashes.

System : Ubuntu, Code::Blocks, GCC, wxWidgets, HIDAPI

Kind regards from
Pier Simon Tilma
Anjum, Netherlands

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2580
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxWidgets and a USB HID device

Post by PB » Thu Sep 10, 2020 7:06 pm

How do you access the GUI elements (wxFrame, wxTextCtrl, etc.) from the worker thread? Just to make sure you know this: anything GUI-related must be accessed only from the main thread aka the GUI thread (i.e., the thread in which wxWidgets were initialized).

If you need to set the GUI from the worker thread, you need to use CallAfter() or ask the GUI thread to do that for you by sending an event. See e.g. here for an example of a worker thread asking the main thread to update the GUI: viewtopic.php?f=1&t=46485&p=194840#p194840

Pier Simon Tilma
Earned a small fee
Earned a small fee
Posts: 11
Joined: Tue Mar 10, 2020 4:52 pm

Re: wxWidgets and a USB HID device

Post by Pier Simon Tilma » Fri Sep 11, 2020 4:53 pm

Anjum, 11-09-2020

Hello PB,

Thank you for your quick response.
anything GUI-related must be accessed only from the main thread aka
the GUI thread (i.e., the thread in which wxWidgets were initialized).
I didn't know this.
.. or ask the GUI thread to do that for you by sending an event.
This is what I did and it works perfect. Now I am able to display data
from Interrupt In reports in various windows.

Kind regards from
Pier Simon Tilma
the Netherlands

Post Reply