Search code examples
c++wxwidgets

wxToggleButton::GetValue() crashes


Access violation error on togglebutton->getValue during runtime in wxwidgets?

 fxButtonYesNo = new wxToggleButton( this, wxID_ANY, wxT("OFF") );
 fxButtonYesNo->Connect( wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, 
           wxCommandEventHandler(fxButtonYesNoState) );


 void fxButtonYesNoState( wxCommandEvent& event )
   { bool fxPressedValue = fxButtonYesNo->GetValue();
     if(fxPressedValue) 
     { fxTextPre->SetLabel("FX ON "); }
      else { fxTextPre->SetLabel("FX OFF "); 

} }>


Solution

  • Ok, the error was found! The Connect function to the togglebutton was not complete and hence an access violation error! The complete Connect function is:

    fxButtonYesNo->Connect( wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, wxCommandEventHandler(fxButtonYesNoState), nulltpr, this );