wxTimer in wxApp::OnInit

crjjrc crjjrc at gmail.com
Thu Feb 7 07:16:28 PST 2008


On Feb 5, 11:45 am, crjjrc <crj... at gmail.com> wrote:

> Is it legal to have a wxTimer start executing in wxApp::OnInit()?  The
> docs for wxTimer say it "can only be used from the main thread."  In
> 2.8.*, my wxTimer triggered just fine in OnInit().  In 2.9, however, I
> don't get any timer events.

I found the cause of this trouble after some head-scratching.  In 2.8,
we had a global, static instance of wxTimer which worked great.  This
didn't work in 2.9 because wxTimer's default constructor relies on
wxTheApp being defined, and apparently it wasn't.  (I got an assertion
error, ""No timer implementation for this platform," from src/common/
timercmn.cpp.)  To workaround this, I just moved the static wxTimer
declaration inside wxApp::OnInit since we didn't really need it as a
global.  And of course the timer events never triggered because the
static wxTimer was destroyed when OnInit finished.  Dynamically
creating it works just fine, or I supposed we could make it a member
variable if need be.

Thanks for listening.

- Chris






More information about the wx-users mailing list