| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 
 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Binding extra arguments</title><meta name="generator" content="DocBook XSL Stylesheets V1.64.1"><link rel="home" href="index.html" title="Programming with gtkmm2"><link rel="up" href="apb.html" title="AppendixB.Signals"><link rel="previous" href="apbs04.html" title="Overriding default signal handlers"><link rel="next" href="apbs06.html" title="X Event signals"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Binding extra arguments</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="apbs04.html">Prev</a></td><th width="60%" align="center">AppendixB.Signals</th><td width="20%" align="right"><a accesskey="n" href="apbs06.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2521268"></a>Binding extra arguments</h2></div></div><div></div></div><p>
If you use one signal handler to catch the same signal from several widgets, you might like that signal handler to receive some extra information. For instance, you might want to know which button was clicked. You can do this with <tt class="literal">SigC::bind()</tt>. Here's some code from the <a href="ch07s02.html#sec-helloworld2" title="An improved Hello World">helloworld2</a> example, which you will encounter later.
</p><pre class="programlisting">
m_button1.signal_clicked().connect( SigC::bind<Glib::ustring>( SigC::slot(*this, &HelloWorld::on_button_clicked), "button 1") );
</pre><p>
This says that we want the signal to send an extra Glib::ustring argument to the signal handler, and that the value of that argument should be "button 1". Of course we will need to add that extra argument to the declaration of our signal handler:
</p><pre class="programlisting">
virtual void on_button_clicked(Glib::ustring data);
</pre><p>
Of course, a normal "clicked" signal handler would have no arguments.
</p><p>
SigC::bind() is not commonly used, but you might find it helpful sometimes. If you are familiar with GTK+ programming then you have probably noticed that this is similar to the extra <tt class="literal">gpointer data</tt> arguments which all GTK+ callbacks have. This is generally overused in GTK+ to pass information that should be stored as member data in a derived Widget, but Widget derivation is very difficult in C. We have far less need of this hack in gtkmm.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="apbs04.html">Prev</a></td><td width="20%" align="center"><a accesskey="u" href="apb.html">Up</a></td><td width="40%" align="right"><a accesskey="n" href="apbs06.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Overriding default signal handlers</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">X Event signals</td></tr></table></div></body></html>
 |