Home > C++, Remobo, Tips > wxWidgets GUI and Multiple Threads

wxWidgets GUI and Multiple Threads

March 26th, 2009

logo9This is an obscure tip, but if you are using wxWidgets as the GUI library in your application, this may come in handy. We currently use it for Remobo and it has served us well as a cross-platform GUI framework.  In particular we are using the C++ lib.

Never try to call any GUI related functions or even instantiate any wxWidgets GUI elements such as Frames and Dialogs from any other thread except the main one!

This is a documented caveat, but for some reason we thought it would be ok to just instantiate a custom wxDialog object in the secondary thread and leave the actual GUI calls to the main thread.  Turns out that even creating the object in a secondary worker thread will cause subsequent UI calls to hang indefinitely.  What made this worse is that it did not show up in MAC OS X but only on Windows…

We just spent a few days on this and it was impossible to find via regular debugging methods since the calls went deep into the Windows UI library… no fun at all. The solution is to call soemthing like wxPostEvent() to post some event from your secondary thread to the main thread and do all your wxWidgets stuff from there… including the wxWindow instantiation.

Share:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • Furl
  • LinkedIn
  • Reddit
  • StumbleUpon
  • TwitThis

Gee C++, Remobo, Tips , ,

  1. No comments yet.
  1. No trackbacks yet.