<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Writing signal handlers</title> <link rel="stylesheet" href="style.css" type="text/css"> <meta name="generator" content="DocBook XSL Stylesheets V1.75.1"> <link rel="home" href="index.html" title="Programming with gtkmm"> <link rel="up" href="chapter-signals.html" title="Appendix B. Signals"> <link rel="prev" href="chapter-signals.html" title="Appendix B. Signals"> <link rel="next" href="sec-disconnecting-signal-handlers.html" title="Disconnecting signal handlers"> </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">Writing signal handlers</th></tr> <tr> <td width="20%" align="left"> <a accesskey="p" href="chapter-signals.html"><img src="icons/prev.png" alt="Prev"></a> </td> <th width="60%" align="center">Appendix B. Signals</th> <td width="20%" align="right"> <a accesskey="n" href="sec-disconnecting-signal-handlers.html"><img src="icons/next.png" alt="Next"></a> </td> </tr> </table> <hr> </div> <div class="sect1" title="Writing signal handlers"> <div class="titlepage"><div><div><h2 class="title" style="clear: both"> <a name="sec-writing-signal-handlers"></a>Writing signal handlers</h2></div></div></div> <p> To find out what type of signal handler you can connect to a signal, you can look it up in the reference documentation or the header file. Here's an example of a signal declaration you might see in the <span class="application">gtkmm</span> headers: </p> <p> </p> <pre class="programlisting"> Glib::SignalProxy1<bool, Gtk::DirectionType> signal_focus() </pre> <p> </p> <p> Other than the signal's name (<code class="literal">focus</code>), two things are important to note here: the number following the word <code class="classname">SignalProxy</code> at the beginning (1, in this case), and the types in the list (<span class="type">bool</span> and <span class="type">Gtk::DirectionType</span>). The number indicates how many arguments the signal handler should have; the first type, <span class="type">bool</span>, is the type that the signal handler should return; and the next type, <span class="type">Gtk::DirectionType</span>, is the type of this signal's first, and only, argument. By looking at the reference documentation, you can see the names of the arguments too. </p> <p> The same principles apply for signals which have more arguments. Here's one with three (taken from <code class="filename"><gtkmm/editable.h></code>): </p> <p> </p> <pre class="programlisting"> Glib::SignalProxy3<void, const Glib::ustring&, int, int*> signal_insert_text() </pre> <p> </p> <p> It follows the same form. The number 3 at the end of the type's name indicates that our signal handler will need three arguments. The first type in the type list is <span class="type">void</span>, so that should be our signal handler's return type. The following three types are the argument types, in order. Our signal handler's prototype could look like this: </p> <p> </p> <pre class="programlisting"> void on_insert_text(const Glib::ustring& text, int length, int* position); </pre> <p> </p> </div> <div class="navfooter"> <hr> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"> <a accesskey="p" href="chapter-signals.html"><img src="icons/prev.png" alt="Prev"></a> </td> <td width="20%" align="center"><a accesskey="u" href="chapter-signals.html"><img src="icons/up.png" alt="Up"></a></td> <td width="40%" align="right"> <a accesskey="n" href="sec-disconnecting-signal-handlers.html"><img src="icons/next.png" alt="Next"></a> </td> </tr> <tr> <td width="40%" align="left" valign="top">Appendix B. Signals </td> <td width="20%" align="center"><a accesskey="h" href="index.html"><img src="icons/home.png" alt="Home"></a></td> <td width="40%" align="right" valign="top"> Disconnecting signal handlers</td> </tr> </table> </div> </body> </html>