WxPanel from thread
Posted: Wed Feb 21, 2018 7:17 pm
Hello,
I have a wxPanel that takes a while to load, because the content of the panel depends on a configuration file that is parsed in the constructor. To avoid annoying users, I want to create this wxPanel in a worker thread. Once the panel is created I would like to it to be added into a wxNotebook in the main thread.
I tried the straight forward approach of calling notebook->AddPage() from the thread, but that fails. I then found a post in which it was explained that wxWidgets objects can not be added from another thread than the main thread. There it was suggested to create a (costume) event to transfer the data to the main thread and then display it there.
So now I am looking for a way to create the wxPanel in a helper thread and send it to the main thread as payload of an event. The event handler should then add it to the wxNotebook.
My question: can I send a complete wxPanel as payload of an event and if so, how should this be done?
I already managed to create an event in a separate thread and have the corresponding event handler update the screen accordingly, but how can I add the payload and what are the limitations?
Thanks in advance, Nico
I have a wxPanel that takes a while to load, because the content of the panel depends on a configuration file that is parsed in the constructor. To avoid annoying users, I want to create this wxPanel in a worker thread. Once the panel is created I would like to it to be added into a wxNotebook in the main thread.
I tried the straight forward approach of calling notebook->AddPage() from the thread, but that fails. I then found a post in which it was explained that wxWidgets objects can not be added from another thread than the main thread. There it was suggested to create a (costume) event to transfer the data to the main thread and then display it there.
So now I am looking for a way to create the wxPanel in a helper thread and send it to the main thread as payload of an event. The event handler should then add it to the wxNotebook.
My question: can I send a complete wxPanel as payload of an event and if so, how should this be done?
I already managed to create an event in a separate thread and have the corresponding event handler update the screen accordingly, but how can I add the payload and what are the limitations?
Thanks in advance, Nico