You could use an Wt:WSignalMapper
, documentation can be found here. With a Wt:WSignalMapper
you can connect multiple senders to a single slot. The multiple senders are in your case the different Wt:WRadioButton
.
Wt::WSignalMapper<Wt:WRadioButton *> * mapper = new Wt::WSignalMapper<
Wt::WRadioButton *>(this);
mapper->mapped().connect(this, &MyWidget::RadioButtonToggle);
// for all radio buttons
mapper->mapConnect(button->changed(), button);
...
You can then use your function RadioButtonToggle
as written above in your question.
Update:
As pointed out in the comments, a Wt:WSignalMapper
is outdated. You should now use boost::bind()
or std::bind()
if you use C++ 11 or higher. The code then becomes:
// for all radio buttons
button->changed().connect(boost::bind(this, &MyWidget::RadioButtonToggle, button));