Author Topic: Using Timer in wxWidgets with wxSmith  (Read 1080 times)

Offline Tomi

  • Single posting newcomer
  • *
  • Posts: 7
    • My website
Using Timer in wxWidgets with wxSmith
« on: January 23, 2024, 02:56:27 pm »
Hello!

I'm using C::B 20.03 and wxWidgets 3.0.x. on Windows 10 (64 bit).
I would like use correctly a timer in my C++ program with wxSmith, but I don't know, how can I add an own function to a created timer at runtime?
I tried so:

Code
wxw30testappFrame::wxw30testappFrame(wxWindow* parent,wxWindowID id)
{
    //(*Initialize(wxw30testappFrame)
    Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("wxID_ANY"));

    Connect(wxEVT_PAINT,(wxObjectEventFunction)&wxw30testappFrame::OnPaint);
    Connect(wxEVT_KEY_DOWN,(wxObjectEventFunction)&wxw30testappFrame::OnKeyDown);
    //*)
    void ScrRefresh(wxTimerEvent& event);
    wxTimer* scrrefresher=new wxTimer();
    scrrefresher->Start(25);
    //scrrefresher->Bind(wxEVT_TIMER,ScrRefresh,this)
    Connect(wxEVT_TIMER,(wxObjectEventFunction)&wxw30testappFrame::ScrRefresh);
}
(...)
void wxw30testappFrame::ScrRefresh(wxTimerEvent& event)
{
    Update();
}

But I get the following error messages after these:
error: 'ScrRefresh' is not a member of 'wxw30testappFrame'
error: no declaration matches 'void wxw30testappFrame::ScrRefresh(wxTimerEvent&)'


Somebody can explain me that what is the correct way to assign a function to a Timer event?

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1563
Re: Using Timer in wxWidgets with wxSmith
« Reply #1 on: January 23, 2024, 04:25:16 pm »
You cannot declare a method inside another method, it should be declared in the class declaration, probably in the protected section.

You are using wxSmith, so let it create the method and Connect() to it. Just add the wxTimer to your frame, select it, click on the curly brackets in the property grid and add an event handler.

Offline Tomi

  • Single posting newcomer
  • *
  • Posts: 7
    • My website
Re: Using Timer in wxWidgets with wxSmith
« Reply #2 on: January 24, 2024, 09:58:16 am »
You are using wxSmith, so let it create the method and Connect() to it. Just add the wxTimer to your frame, select it, click on the curly brackets in the property grid and add an event handler.
Hello Miguel!

I tried this solution and it finally works now; thanks! But what if I would like create a Timer at runtime? Where is its place and how can I declare it? I didn't find anything about it on the Internet.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1563
Re: Using Timer in wxWidgets with wxSmith
« Reply #3 on: January 24, 2024, 11:10:04 am »
Just copy what wxSmith did, but outside the //(* ... //*) block: declare a method, define the method and Connect() or Bind() to it.