tobkit/libsigc++-2.2.3/docs/manual/html/ch02.html
Antonio Niño Díaz cc2d654195 Remove build artifacts of libsigc++-2.2.3
In practice, the whole folder has been removed and replaced by a fresh
copy of libsigc++-2.2.3 from here:

http://repository.timesys.com/buildsources/l/libsigc++/libsigc++-2.2.3/
2024-07-26 02:09:17 +01:00

34 lines
3.9 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 2. Connecting your code to signals</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="LibSigC++"><link rel="up" href="index.html" title="LibSigC++"><link rel="prev" href="ch01.html" title="Chapter 1. Introduction"><link rel="next" href="ch02s02.html" title="Using a member function"></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">Chapter 2. Connecting your code to signals</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch01.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ch02s02.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="sec-connecting"></a>Chapter 2. Connecting your code to signals</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="ch02.html#id2521776">A simple example</a></span></dt><dt><span class="sect1"><a href="ch02s02.html">Using a member function</a></span></dt><dt><span class="sect1"><a href="ch02s03.html">Signals with parameters</a></span></dt><dt><span class="sect1"><a href="ch02s04.html">Disconnecting</a></span></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2521776"></a>A simple example</h2></div></div></div><p>So to get some experience, lets look at a simple example...</p><p>Lets say you and I are writing an application which informs the user when
aliens land in the car park. To keep the design nice and clean, and allow for
maximum portability to different interfaces, we decide to use LibSigC++ to
split the project in two parts.</p><p>I will write the <code class="literal">AlienDetector</code> class, and you will write the code to inform
the user. (Well, OK, I'll write both, but we're pretending, remember?)</p><p>Here's my class:</p><pre class="programlisting">
class AlienDetector
{
public:
AlienDetector();
void run();
sigc::signal&lt;void&gt; signal_detected;
};
</pre><p>(I'll explain the type of signal_detected later.)</p><p>Here's your code that uses it:</p><pre class="programlisting">
void warn_people()
{
cout &lt;&lt; "There are aliens in the carpark!" &lt;&lt; endl;
}
int main()
{
AlienDetector mydetector;
mydetector.signal_detected.connect( sigc::ptr_fun(warn_people) );
mydetector.run();
return 0;
}
</pre><p>Pretty simple really - you call the <code class="literal">connect()</code> method on the signal to
connect your function. <code class="literal">connect()</code> takes a <code class="literal">slot</code> parameter (remember slots
are capable of holding any type of callback), so you convert your
<code class="literal">warn_people()</code> function to a slot using the <code class="literal">slot()</code> function.</p><p>To compile this example from the downloadable example code, use:</p><pre class="programlisting">g++ example1.cc -o eg1 `pkg-config --cflags --libs sigc++-2.0`</pre><p>Note that those `` characters are backticks, not single quotes. Run it with</p><pre class="programlisting">./eg1</pre><p>(Try not to panic when the aliens land!)</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch01.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="ch02s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 1. Introduction </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Using a member function</td></tr></table></div></body></html>