Imported Upstream version 2.99.2
[platform/upstream/libsigc++.git] / docs / reference / html / group__slot.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5 <meta http-equiv="X-UA-Compatible" content="IE=9"/>
6 <meta name="generator" content="Doxygen 1.8.9.1"/>
7 <title>libsigc++: Slots</title>
8 <link href="tabs.css" rel="stylesheet" type="text/css"/>
9 <script type="text/javascript" src="jquery.js"></script>
10 <script type="text/javascript" src="dynsections.js"></script>
11 <link href="doxygen.css" rel="stylesheet" type="text/css" />
12 <link href="doxygen-extra.css" rel="stylesheet" type="text/css"/>
13 </head>
14 <body>
15 <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
16 <div id="titlearea">
17 <table cellspacing="0" cellpadding="0">
18  <tbody>
19  <tr style="height: 56px;">
20   <td style="padding-left: 0.5em;">
21    <div id="projectname">libsigc++
22    &#160;<span id="projectnumber">2.99.2</span>
23    </div>
24   </td>
25  </tr>
26  </tbody>
27 </table>
28 </div>
29 <!-- end header part -->
30 <!-- Generated by Doxygen 1.8.9.1 -->
31   <div id="navrow1" class="tabs">
32     <ul class="tablist">
33       <li><a href="index.html"><span>Main&#160;Page</span></a></li>
34       <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
35       <li><a href="modules.html"><span>Modules</span></a></li>
36       <li><a href="namespaces.html"><span>Namespaces</span></a></li>
37       <li><a href="annotated.html"><span>Classes</span></a></li>
38     </ul>
39   </div>
40 </div><!-- top -->
41 <div class="header">
42   <div class="summary">
43 <a href="#nested-classes">Classes</a>  </div>
44   <div class="headertitle">
45 <div class="title">Slots<div class="ingroups"><a class="el" href="group__sigcfunctors.html">Functors</a></div></div>  </div>
46 </div><!--header-->
47 <div class="contents">
48
49 <p>Slots are type-safe representations of callback methods and functions.  
50 <a href="#details">More...</a></p>
51 <table class="memberdecls">
52 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="nested-classes"></a>
53 Classes</h2></td></tr>
54 <tr class="memitem:"><td class="memItemLeft" align="right" valign="top">class &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsigc_1_1slot.html">sigc::slot&lt; T_return, T_arg &gt;</a></td></tr>
55 <tr class="memdesc:"><td class="mdescLeft">&#160;</td><td class="mdescRight">Converts an arbitrary functor to a unified type which is opaque.  <a href="classsigc_1_1slot.html#details">More...</a><br /></td></tr>
56 <tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
57 <tr class="memitem:"><td class="memItemLeft" align="right" valign="top">class &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classsigc_1_1slot__base.html">sigc::slot_base</a></td></tr>
58 <tr class="memdesc:"><td class="mdescLeft">&#160;</td><td class="mdescRight">Base type for slots.  <a href="classsigc_1_1slot__base.html#details">More...</a><br /></td></tr>
59 <tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
60 </table>
61 <a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
62 <p>Slots are type-safe representations of callback methods and functions. </p>
63 <p>A slot can be constructed from any function object or function, regardless of whether it is a global function, a member method, static, or virtual.</p>
64 <p>Use the <a class="el" href="group__mem__fun.html#ga6ed5c519845b36eb7c6461ebd2a073c9" title="Creates a functor of type sigc::mem_functor which wraps a method. ">sigc::mem_fun()</a> and <a class="el" href="group__ptr__fun.html#ga203dd1ac5747cf2f3d2b2d590ad32e82" title="Creates a functor of type sigc::pointer_functor which wraps an existing non-member function...">sigc::ptr_fun()</a> template functions to get a <a class="el" href="classsigc_1_1slot.html" title="Converts an arbitrary functor to a unified type which is opaque. ">sigc::slot</a>, like so: </p><div class="fragment"><div class="line"><a class="code" href="classsigc_1_1slot.html">sigc::slot&lt;void(int)&gt;</a> sl = <a class="code" href="group__mem__fun.html#ga6ed5c519845b36eb7c6461ebd2a073c9">sigc::mem_fun</a>(someobj,&amp; SomeClass::somemethod);</div>
65 </div><!-- fragment --><p> or </p><div class="fragment"><div class="line"><a class="code" href="classsigc_1_1slot.html">sigc::slot&lt;void(int)&gt;</a> sl = <a class="code" href="group__ptr__fun.html#ga203dd1ac5747cf2f3d2b2d590ad32e82">sigc::ptr_fun</a>(&amp;somefunction);</div>
66 </div><!-- fragment --><p> or, in gtkmm, </p><div class="fragment"><div class="line">m_Button.signal_clicked().connect( <a class="code" href="group__mem__fun.html#ga6ed5c519845b36eb7c6461ebd2a073c9">sigc::mem_fun</a>(*<span class="keyword">this</span>, &amp;MyWindow::on_button_clicked) );</div>
67 </div><!-- fragment --><p>The compiler will complain if SomeClass::somemethod, etc. have the wrong signature.</p>
68 <p>You can also pass slots as method parameters where you might normally pass a function pointer.</p>
69 <p><a class="el" href="group__mem__fun.html#ga6ed5c519845b36eb7c6461ebd2a073c9" title="Creates a functor of type sigc::mem_functor which wraps a method. ">sigc::mem_fun()</a> and <a class="el" href="group__ptr__fun.html#ga203dd1ac5747cf2f3d2b2d590ad32e82" title="Creates a functor of type sigc::pointer_functor which wraps an existing non-member function...">sigc::ptr_fun()</a> return functors, but those functors are not slots. </p><div class="fragment"><div class="line"><a class="code" href="classsigc_1_1slot.html">sigc::slot&lt;void(int)&gt;</a> sl = <a class="code" href="group__mem__fun.html#ga6ed5c519845b36eb7c6461ebd2a073c9">sigc::mem_fun</a>(someobj,&amp; SomeClass::somemethod);</div>
70 </div><!-- fragment --><p> is not equivalent to </p><div class="fragment"><div class="line"><span class="keyword">auto</span> sl = <a class="code" href="group__mem__fun.html#ga6ed5c519845b36eb7c6461ebd2a073c9">sigc::mem_fun</a>(someobj, &amp;SomeClass::somemethod); <span class="comment">// Not a slot!</span></div>
71 </div><!-- fragment --><p>A C++11 lambda expression is a functor (function object). It is automatically wrapped in a slot, if it is connected to a signal. </p><div class="fragment"><div class="line"><span class="keyword">auto</span> on_response = [&amp;someobj] (<span class="keywordtype">int</span> response_id)</div>
72 <div class="line">  {</div>
73 <div class="line">    someobj.somemethod(response_id);</div>
74 <div class="line">    somefunction(response_id);</div>
75 <div class="line">  };</div>
76 <div class="line">m_Dialog.signal_response().connect(on_response);</div>
77 </div><!-- fragment --><p>If you connect a C++11 lambda expression or a std::function&lt;&gt; instance to a signal or assign it to a slot,</p><ul>
78 <li>With libsigc++ versions before 2.6, if the return type is not void, you must use the <a class="el" href="group__sigcfunctors.html#gadf1ba3cacb09cc5c3c3e399836ec6e50" title="Helper macro, if you want to mix user-defined and third party functors with libsigc++. ">SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE</a> macro,</li>
79 <li>if your functor contains references to <a class="el" href="structsigc_1_1trackable.html" title="Base class for objects with auto-disconnection. ">sigc::trackable</a> derived objects, those objects will not be tracked, unless you also use <a class="el" href="group__track__obj.html#ga2d8c46509a25df9c7ad37b8712d16ab1" title="Creates an adaptor of type sigc::track_obj_functor which wraps a functor. ">sigc::track_obj()</a>. </li>
80 </ul>
81 </div><!-- contents -->
82 <!-- start footer part -->
83 <hr class="footer"/><address class="footer"><small>
84 Generated on Wed Mar 16 2016 20:53:27 for libsigc++ by &#160;<a href="http://www.doxygen.org/index.html">
85 <img class="footer" src="doxygen.png" alt="doxygen"/>
86 </a> 1.8.9.1
87 </small></address>
88 </body>
89 </html>