Object attributes and events
Posted: Sat Mar 03, 2012 3:08 pm
The problem was that I was connecting a button clicked event with the button itself.
When I did that, the boost::weak_ptr attribute was messed up.
Why does it matter will I connect to the button or to the object which holds the weak_ptr?
The code should illustrate. I have commented out the problematic event connecting.
When I did that, the boost::weak_ptr attribute was messed up.
Why does it matter will I connect to the button or to the object which holds the weak_ptr?
The code should illustrate. I have commented out the problematic event connecting.
Code: Select all
class App : public wxApp
{
public:
virtual bool OnInit();
virtual int OnExit();
void buttonClicked(wxCommandEvent& event);
// stuff to initiate the weak_ptr
private:
boost::weak_ptr<MailBox> mailBox;
};
bool App::OnInit()
{
// Stuff
// button->Connect(wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(App::buttonClicked));
Connect(button->GetId(), wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(App::buttonClicked));
}
void App::buttonClicked(wxCommandEvent& event)
{
shared_ptr<MailBox> mail(this->mailBox.lock());
if (mail) {
// will never happen when button->Connect used
}
}