Reputation: 915
I'm working on a gtkmm program and I would like to have a button that, when pressed, changes a given variable. For intensive purposes lets say I can't make this variable global. Is it still possible to call something like:
m_button2.signal_clicked().connect(sigc::ptr_fun(&on_player_button_clicked));
where on_player_button_clicked is the method that's called when button2 is pressed, but also pass it a parameter. So I want my button, when pressed, to call my method like this:
int parameter
m_button2.signal_clicked().connect(sigc::ptr_fun(&on_player_button_clicked(parameter)));
If this is not possible, is there any way for me to get my button to change this variable without making the variable global?
Upvotes: 1
Views: 932
Reputation: 2193
In terms of design, at least OO design, first decide who owns the variable.
Then, the idea is to send that owner a message, "Mr owner, I command you to change the variable". You can do this by emitting a "variable_needs_change" signal and have the owner listen to it, or give the owner a setter method and have the button use it (by giving the callback function access to a referece to the owner).
But putting it aside, there's the simple option of binding. This is the staright-forward solution: use sigc::bind to add an argument. There's an example for this in the gtkmm book, if I'm not mistaken (and probably in the sigc++ tutorial too).
Upvotes: 1