1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="highlight.min.css">
<script src="highlight.min.js"></script><script>
hljs.configure({languages: ['cpp']});
hljs.highlightAll();
</script><title>Appendix D. Comparison with other signalling systems</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
<link rel="home" href="index.html" title="Programming with gtkmm 4">
<link rel="up" href="index.html" title="Programming with gtkmm 4">
<link rel="prev" href="chapter-custom-signals.html" title="Appendix C. Creating your own signals">
<link rel="next" href="sec-windows-installation.html" title="Appendix E. gtkmm and Win32">
</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">Appendix D. Comparison with other signalling systems</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="chapter-custom-signals.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<th width="60%" align="center"> </th>
<td width="20%" align="right"> <a accesskey="n" href="sec-windows-installation.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
</table>
<hr>
</div>
<div class="appendix">
<div class="titlepage"><div><div><h1 class="title">
<a name="sec-signals-comparison"></a>Appendix D. Comparison with other signalling systems</h1></div></div></div>
<p>
(An aside: <span class="application">GTK</span> calls this scheme "signalling"; the
sharp-eyed reader with GUI toolkit experience will note that this same design
is often
seen under the name of "broadcaster-listener" (e.g., in Metrowerks'
PowerPlant framework for the Macintosh). It works in much the same
way: one sets up <code class="literal">broadcasters</code>, and then connects
<code class="literal">listeners</code> to them; the broadcaster keeps a list of the
objects listening to it, and when someone gives the broadcaster a
message, it calls all of its objects in its list with the message. In
<span class="application">gtkmm</span>, signal objects play the role of broadcasters, and slots
play the role of listeners - sort of. More on this later.)
</p>
<p>
<span class="application">gtkmm</span> signal handlers are strongly-typed, whereas
<span class="application">GTK</span> C code allows you to connect a callback with
the wrong number and type of arguments, leading to a segfault at runtime. And,
unlike <span class="application">Qt</span>, <span class="application">gtkmm</span> achieves this without modifying
the C++ language.</p>
<p>
Re. Overriding signal handlers: You can do this in the straight-C world of GTK too; that's what GTK's
object system is for. But in GTK, you have to go through some
complicated procedures to get object-oriented features like
inheritance and overloading. In C++, it's simple, since those
features are supported in the language itself; you can let the
compiler do the dirty work.
</p>
<p>
This is one of the places where the beauty of C++ really comes out.
One wouldn't think of subclassing a GTK widget simply to override its
action method; it's just too much trouble. In GTK, you almost always
use signals to get things done, unless you're writing a new widget.
But because overriding methods is so easy in C++, it's entirely
practical - and sensible - to subclass a button for that purpose.
</p>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="chapter-custom-signals.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<td width="20%" align="center"> </td>
<td width="40%" align="right"> <a accesskey="n" href="sec-windows-installation.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Appendix C. Creating your own 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"> Appendix E. <span class="application">gtkmm</span> and Win32</td>
</tr>
</table>
</div>
</body>
</html>
|