Error passing wxCommandEvent to wxQueueEvent 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
MagickPanda
Experienced Solver
Experienced Solver
Posts: 81
Joined: Wed Oct 19, 2016 1:41 pm

Error passing wxCommandEvent to wxQueueEvent

Post by MagickPanda »

I was trying to queue a wxCommandEvent event object via wxQueueEvent, but it seems wxQueueEvent function only takes wxEvent base type, hence the error.

Though the non-thread-safe version wxPostEvent works fine, and I don't think simply dynamically cast wxCommandEvent to its base class is a good idea to bypass this error.

Any tips will be appreciated.
Thanks.

this is from samples event code:

Code: Select all

void MyFrame::OnFireCustom(wxCommandEvent& WXUNUSED(event))
{
    wxCommandEvent eventCustom(wxEVT_MY_CUSTOM_COMMAND);

    wxPostEvent(this, eventCustom);
}
wxQueueEvent:

Code: Select all

void MyFrame::OnFireCustom(wxCommandEvent& WXUNUSED(event))
{
    wxCommandEvent eventCustom(wxEVT_MY_CUSTOM_COMMAND);

    wxQueueEvent(this, eventCustom); ///error: cannot convert wxCommandEvent* to wxEvent*
}
User avatar
doublemax
Moderator
Moderator
Posts: 19159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Error passing wxCommandEvent to wxQueueEvent

Post by doublemax »

Try this:

Code: Select all

void MyFrame::OnFireCustom(wxCommandEvent& WXUNUSED(event))
{
    wxCommandEvent *eventCustom = new wxCommandEvent (wxEVT_MY_CUSTOM_COMMAND);
    eventCustom ->SetEventObject(this);
    wxQueueEvent(this, eventCustom);
}
Use the source, Luke!
coderrc
Earned some good credits
Earned some good credits
Posts: 141
Joined: Tue Nov 01, 2016 2:46 pm

Re: Error passing wxCommandEvent to wxQueueEvent

Post by coderrc »

you have to use a pointer.
try

Code: Select all

void MyFrame::OnFireCustom(wxCommandEvent& WXUNUSED(event))
{
    wxCommandEvent* evt = new wxCommandEvent(wxEVT_MY_CUSTOM_COMMAND);

    GetEventHandler()->QueueEvent(evt); 
}
QueueEvent takes possession of the pointer so don't delete it
MagickPanda
Experienced Solver
Experienced Solver
Posts: 81
Joined: Wed Oct 19, 2016 1:41 pm

Re: Error passing wxCommandEvent to wxQueueEvent

Post by MagickPanda »

Thank you both for the help. I thought the wxQueueEvent takes a reference and make a copy of event object,thanks again.
Post Reply