More bind related issues... 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
ouch67
Earned some good credits
Earned some good credits
Posts: 135
Joined: Sun Mar 23, 2008 12:09 am

More bind related issues...

Post by ouch67 » Fri Jul 15, 2011 5:19 pm

so I have this code:

Code: Select all

class wxTimerLoop
{
    public:
//looping timer vars----------------------------------------------------
    wxTimer* timerloop[];
        wxTimerLoop(wxEvtHandler* evthandler, void(*the_function)(wxTimerEvent&), int event_id = -1, int loop_time = 1000, bool one_shot = false){
            int x = 0;

            while(timerloop[x]){
                    x++;
            }

            if(!timerloop[x]){
                timerloop[x] = new wxTimer;
                timerloop[x]->SetOwner(evthandler,event_id);
                evthandler->Bind(wxEVT_TIMER, the_function, event_id);
                timerloop[x]->Start(loop_time, one_shot);
            }

        }
};
I'm trying to call bind for an window passed as an event handler. Problem is I get an "cannot be used as a function" on bind. Anyone have any ideas how to use bind "remotely" like this?
Last edited by ouch67 on Fri Jul 15, 2011 7:51 pm, edited 2 times in total.

User avatar
doublemax
Moderator
Moderator
Posts: 15068
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: More bind related issues...

Post by doublemax » Fri Jul 15, 2011 7:21 pm

What's the exact error message at what code line?
This code is not very "test-friendly", so i can only make some guesses.

Code: Select all

wxTimerLoop(wxEvtHandler* evthandler, void(*the_function)(wxTimerEvent *), int event_id = -1, int loop_time = 1000, bool one_shot = false){
The "wxTimerEvent *" looks suspicious as event handling functions usually take references.

Code: Select all

evthandler->Bind(wxEVT_TIMER, &the_function, event_id);
Same here with the "&the_function".
Use the source, Luke!

ouch67
Earned some good credits
Earned some good credits
Posts: 135
Joined: Sun Mar 23, 2008 12:09 am

Re: More bind related issues...

Post by ouch67 » Fri Jul 15, 2011 7:33 pm

The whole error is:

Code: Select all

C:\wxwidgets\wxWidgets\include\wx\event.h|505|error: '((wxEventFunctorFunctor<wxEventTypeTag<wxTimerEvent>, void (**)(wxTimerEvent&)>*)this)->wxEventFunctorFunctor<wxEventTypeTag<wxTimerEvent>, void (**)(wxTimerEvent&)>::m_handler' cannot be used as a function|
but the function is supposed to just declare a timer, set up a bind and start it.

so:

Code: Select all

void OnTimer(wxTimerEvent& event)
{
   wxMessageBox("timer 1 says hi");
}
wxTimerLoop(this,&OnTimer,1,3000);
in theory of course... :)

edit: yes I was declaring things wrong. I'm so used to tossing pointers around I din't event look at my &'s and *'s... :)

Post Reply