signals - Anyway to pass parameters to a method called when a Gtkmm button is pressed? -


i'm working on gtkmm program , have button that, when pressed, changes given variable. intensive purposes lets can't make variable global. still possible call like:

m_button2.signal_clicked().connect(sigc::ptr_fun(&on_player_button_clicked)); 

where on_player_button_clicked method that's called when button2 pressed, pass parameter. want button, when pressed, call method this:

int parameter m_button2.signal_clicked().connect(sigc::ptr_fun(&on_player_button_clicked(parameter))); 

if not possible, there way me button change variable without making variable global?

in terms of design, @ least oo design, first decide owns variable.

then, idea send owner message, "mr owner, command change variable". can emitting "variable_needs_change" signal , have owner listen it, or give owner setter method , have button use (by giving callback function access referece owner).

but putting aside, there's simple option of binding. staright-forward solution: use sigc::bind add argument. there's example in gtkmm book, if i'm not mistaken (and in sigc++ tutorial too).


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -