What's wrong with the wxEvtHandler::Connect ? 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
manianis
Experienced Solver
Experienced Solver
Posts: 72
Joined: Mon Jan 15, 2007 11:00 am

What's wrong with the wxEvtHandler::Connect ?

Post by manianis » Tue Jan 30, 2007 8:03 pm

I want to display the tooltip of a wxBitmapButton on a wxStaticText assuming

m_btnSave is the pointer to a constrcuted wxBitmapButton
and
m_lblComment is the pointer to a constrcuted wxStaticText I wrote this event handler for the wxEVT_WINDOW_WINDOW :

The ctor code :

Code: Select all

m_btnSave->Connect(wxID_ANY, wxID_ANY, wxEVT_ENTER_WINDOW, (wxObjectEventFunction)&ClientInfoPanel::OnEnterWindowSave, m_btnSave, this);
The handler function :

Code: Select all

void ClientInfoPanel::OnEnterWindowSave(wxMouseEvent& event)
{
	wxBitmapButton *btnBmp = (wxBitmapButton *)event.GetEventObject();
	m_lblComment->SetLabel(btnBmp->GetToolTip()->GetTip()); //);
	// ((MainFrame *)&wxTopLevelWindow())->SetStatusText(m_btnSave->GetToolTip()->GetTip());
}
When I close the application frame it shows an error :
  • ---------------------------
    ClientCredit.exe - Application Error
    ---------------------------
    The exception unknown software exception (0xc00000fd) occurred in the application at location 0x006e6339.
I don't know what's the problem. Help me please...

clyde729
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Mon May 29, 2006 10:50 pm
Location: Jena, Germany

Post by clyde729 » Tue Jan 30, 2007 9:29 pm

Try to disconnect before the window(s) will be destroyed. So in panel's or frame's destructor, or, for the latter one, when catching the onClose event.

There could happen some mouse events, even if the bitmapbutton itself is already destroyed. So your pointer to the "save" button isn't valid anymore.
OS: Windows XP Home, Compiler: MingW, Version: wxWidgets 2.8.0, IDE: wx-Devcpp

manianis
Experienced Solver
Experienced Solver
Posts: 72
Joined: Mon Jan 15, 2007 11:00 am

Post by manianis » Tue Jan 30, 2007 10:01 pm

Thank you Clyde729 It's as you said when I close the Frame the m_btnSave get destroyed twice with an invalid pointer the second time and that's generated the error.

I've corrected by changing :

Code: Select all

m_btnSave->Connect(wxID_ANY, wxID_ANY, wxEVT_ENTER_WINDOW, (wxObjectEventFunction)&ClientInfoPanel::OnEnterWindowSave, m_btnSave, this);
to

Code: Select all

m_btnSave->Connect(wxID_ANY, wxID_ANY, wxEVT_ENTER_WINDOW, (wxObjectEventFunction)&ClientInfoPanel::OnEnterWindowSave, NULL, this);
because in the event.GetEventObject(); returned the m_btnSave object I wanted to send in the Connect function.

Post Reply