wxTimer question 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
cr0nholio
Knows some wx things
Knows some wx things
Posts: 29
Joined: Wed Sep 12, 2007 8:54 am

wxTimer question

Post by cr0nholio » Thu Nov 22, 2007 4:09 pm

I am trying to put a wxTimer into an already existing application. The GUI is built using wxFormBuilder. I tried following the example given here.

Code: Select all

class MyFrame : public wxFrame
{
public:
    ...
    void OnTimer(wxTimerEvent& event);

private:
    wxTimer m_timer;
};

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
    EVT_TIMER(TIMER_ID, MyFrame::OnTimer)
END_EVENT_TABLE()

MyFrame::MyFrame()
       : m_timer(this, TIMER_ID)
{
    m_timer.Start(1000);    // 1 second interval
}

void MyFrame::OnTimer(wxTimerEvent& event)
{
    // do whatever you want to do every second here
}
However, I cannot add the timer to the GUIFrame class (inherits from wxFrame) that I get from wxFormBuilder because the GUIFrame.h file will be overwritten each time I change the GUI. So, I tried adding it to my application's main class which in turn inherits from GUIFrame.

That generates compile errors for the event table code:

Code: Select all

error: ISO C++ does not permit wxFrameBase::sm_eventTable to be defined as myAppFrame::sm_eventTable
error: const wxEventTableEntry wxFrameBase::sm_eventTableEntries [] is private within this context
error: no const wxEventTable* myAppFrame::GetEventTable() const member function declared in class myAppFrame
And a similar one for HashTable. Plus, I can't do this:

Code: Select all

myAppFrame::myAppFrame()
       : m_timer(this, TIMER_ID)
Because it's supposed to inherit from GUIFrame:

Code: Select all

myAppFrame::myAppFrame(wxFrame *frame)
   : GUIFrame(frame)
So what am I doing wrong?

meisjohn
Earned a small fee
Earned a small fee
Posts: 22
Joined: Sat Nov 18, 2006 2:01 pm
Location: US/Pennsylvania

Post by meisjohn » Thu Nov 22, 2007 5:37 pm

Did you declare the event table for myAppFrame using the "DECLARE_EVENT_TABLE()" macro?

It looks as though when you begin the event table, it thinks you're trying to override the base class's event table.

John.

User avatar
tierra
Site Admin
Site Admin
Posts: 1343
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Re: wxTimer question

Post by tierra » Thu Nov 22, 2007 9:10 pm

As for you're initialization list, it can be done like this:

Code: Select all

MyFrame::MyFrame()
: GUIFrame(frame),
  m_timer(this, TIMER_ID)

cr0nholio
Knows some wx things
Knows some wx things
Posts: 29
Joined: Wed Sep 12, 2007 8:54 am

Post by cr0nholio » Fri Nov 23, 2007 8:33 am

Thanks guys! It works now. I must admit I never quite got the hang of event tables because wxFormBuilder was taking care of that until now. :wink:

Post Reply