1 | <html> |
---|
2 | <head> |
---|
3 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
---|
4 | <title>Frequently Asked Questions</title> |
---|
5 | <link rel="stylesheet" href="../boostbook.css" type="text/css"> |
---|
6 | <meta name="generator" content="DocBook XSL Stylesheets V1.68.1"> |
---|
7 | <link rel="start" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset"> |
---|
8 | <link rel="up" href="../signals.html" title="Chapter 12. Boost.Signals"> |
---|
9 | <link rel="prev" href="../id1010153-bb.html" title="Class last_value<void>"> |
---|
10 | <link rel="next" href="s05.html" title="Design Overview"> |
---|
11 | </head> |
---|
12 | <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> |
---|
13 | <table cellpadding="2" width="100%"> |
---|
14 | <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td> |
---|
15 | <td align="center"><a href="../../../index.htm">Home</a></td> |
---|
16 | <td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td> |
---|
17 | <td align="center"><a href="../../../people/people.htm">People</a></td> |
---|
18 | <td align="center"><a href="../../../more/faq.htm">FAQ</a></td> |
---|
19 | <td align="center"><a href="../../../more/index.htm">More</a></td> |
---|
20 | </table> |
---|
21 | <hr> |
---|
22 | <div class="spirit-nav"> |
---|
23 | <a accesskey="p" href="../id1010153-bb.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../signals.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="s05.html"><img src="../images/next.png" alt="Next"></a> |
---|
24 | </div> |
---|
25 | <div class="section" lang="en"> |
---|
26 | <div class="titlepage"><div><div><h2 class="title" style="clear: both"> |
---|
27 | <a name="id1633680"></a>Frequently Asked Questions</h2></div></div></div> |
---|
28 | <div class="qandaset"> |
---|
29 | <dl> |
---|
30 | <dt>1. <a href="s04.html#id1633688">Don't noncopyable signal semantics mean that a class |
---|
31 | with a signal member will be noncopyable as well?</a> |
---|
32 | </dt> |
---|
33 | <dt>2. <a href="s04.html#id1633711">Is Boost.Signals thread-safe?</a> |
---|
34 | </dt> |
---|
35 | <dt>3. <a href="s04.html#id1633734">How do I get Boost.Signals to work with Qt?</a> |
---|
36 | </dt> |
---|
37 | </dl> |
---|
38 | <table border="0" summary="Q and A Set"> |
---|
39 | <col align="left" width="1%"> |
---|
40 | <tbody> |
---|
41 | <tr class="question"> |
---|
42 | <td align="left" valign="top"> |
---|
43 | <a name="id1633688"></a><a name="id1633690"></a><b>1.</b> |
---|
44 | </td> |
---|
45 | <td align="left" valign="top"><p>Don't noncopyable signal semantics mean that a class |
---|
46 | with a signal member will be noncopyable as well?</p></td> |
---|
47 | </tr> |
---|
48 | <tr class="answer"> |
---|
49 | <td align="left" valign="top"><b></b></td> |
---|
50 | <td align="left" valign="top"><p>No. The compiler will not be able to generate a copy |
---|
51 | constructor or copy assignment operator for your class if it |
---|
52 | has a signal as a member, but you are free to write your own |
---|
53 | copy constructor and/or copy assignment operator. Just don't |
---|
54 | try to copy the signal.</p></td> |
---|
55 | </tr> |
---|
56 | <tr class="question"> |
---|
57 | <td align="left" valign="top"> |
---|
58 | <a name="id1633711"></a><a name="id1633713"></a><b>2.</b> |
---|
59 | </td> |
---|
60 | <td align="left" valign="top"><p>Is Boost.Signals thread-safe?</p></td> |
---|
61 | </tr> |
---|
62 | <tr class="answer"> |
---|
63 | <td align="left" valign="top"><b></b></td> |
---|
64 | <td align="left" valign="top"><p>No. Using Boost.Signals in a multithreaded concept is |
---|
65 | very dangerous, and it is very likely that the results will be |
---|
66 | less than satisfying. Even trying to invoke the same signal from |
---|
67 | two different threads is dangerous. Although we would like to |
---|
68 | make Signals thread-safe, it is unlikely to happen without |
---|
69 | help from other developers.</p></td> |
---|
70 | </tr> |
---|
71 | <tr class="question"> |
---|
72 | <td align="left" valign="top"> |
---|
73 | <a name="id1633734"></a><a name="id1633736"></a><b>3.</b> |
---|
74 | </td> |
---|
75 | <td align="left" valign="top"><p>How do I get Boost.Signals to work with Qt?</p></td> |
---|
76 | </tr> |
---|
77 | <tr class="answer"> |
---|
78 | <td align="left" valign="top"><b></b></td> |
---|
79 | <td align="left" valign="top"> |
---|
80 | <p>When building with Qt, the Moc keywords |
---|
81 | <code class="computeroutput">signals</code> and <code class="computeroutput">slots</code> are defined using |
---|
82 | preprocessor macros, causing programs using Boost.Signals and |
---|
83 | Qt together to fail to compile.</p> |
---|
84 | <p><span class="emphasis"><em>For Qt 4.1 and later</em></span>, This behavior |
---|
85 | can be turned off in Qt on a per-project or per-file basis |
---|
86 | with the <code class="computeroutput">no_keywords</code> option. This works with |
---|
87 | out-of-the-box builds of Boost and Qt. You do not need to |
---|
88 | re-configure, re-build, or duplicate existing libraries. For a |
---|
89 | project where you want to use both Boost.Signals and Qt |
---|
90 | Signals and Slots, the relevant part of your .pro file might |
---|
91 | look like this:</p> |
---|
92 | <pre class="programlisting"> |
---|
93 | CONFIG += no_keywords # so Qt won't #define any non-all-caps `keywords' |
---|
94 | INCLUDEPATH += . /usr/local/include/boost-1_33_1/ |
---|
95 | macx:LIBS += /usr/local/lib/libboost_signals-1_33_1.a # ...your exact paths may vary |
---|
96 | </pre> |
---|
97 | <p>Now you can mix Boost.Signals and Qt Signals and Slots |
---|
98 | in the same files, and even within the same class or function. |
---|
99 | You will have to use the upper-case versions of Qt macros in |
---|
100 | your own code. See the article <a href="http://scottcollins.net/articles/a-deeper-look-at-signals-and-slots.html" target="_top">A |
---|
101 | Deeper Look at Signals and Slots</a> [off-site] for more |
---|
102 | complete examples and a survey of the strengths of the two |
---|
103 | systems.</p> |
---|
104 | <p><span class="emphasis"><em>Older versions of Qt</em></span> did not |
---|
105 | provide a reliable mechanism for avoiding these unfriendly, |
---|
106 | all lower-case `keyword'-like macros. Although this is a |
---|
107 | problem with Qt and not Boost.Signals, a user can use the two |
---|
108 | systems together with a little extra effort. There are two |
---|
109 | ways to do this:</p> |
---|
110 | <p>The first way involves defining |
---|
111 | the <code class="computeroutput">BOOST_SIGNALS_NAMESPACE</code> |
---|
112 | macro to some other identifier (e.g., <code class="computeroutput">signalslib</code>) |
---|
113 | when building and using the Boost.Signals library. Then the |
---|
114 | namespace of the Boost.Signals library will be |
---|
115 | <code class="computeroutput">boost::BOOST_SIGNALS_NAMESPACE</code> instead of |
---|
116 | <code class="computeroutput">boost::signals</code>. To retain the original namespace |
---|
117 | name in translation units that do not interact with Qt, you |
---|
118 | can use a namespace alias:</p> |
---|
119 | <pre class="programlisting"> |
---|
120 | namespace boost { |
---|
121 | namespace signals = BOOST_SIGNALS_NAMESPACE; |
---|
122 | } |
---|
123 | </pre> |
---|
124 | <p>The second way, provided by Frank Hess, involves |
---|
125 | creating a header <code class="computeroutput">signalslib.hpp</code> that contains |
---|
126 | the following code:</p> |
---|
127 | <pre class="programlisting">#ifdef signals |
---|
128 | #error "signalslib.hpp must be included before any qt header" |
---|
129 | #endif |
---|
130 | |
---|
131 | #include <boost/signal.hpp> |
---|
132 | namespace boost |
---|
133 | { |
---|
134 | namespace signalslib = signals; |
---|
135 | }</pre> |
---|
136 | <p>This header must be included before any Qt headers. Once |
---|
137 | it has been included, you can refer to the Signals library via |
---|
138 | the namespace <code class="computeroutput">boost::signalslib</code>. This option is |
---|
139 | preferable to the first option because it can be used without |
---|
140 | recompiling the Signals library binary. </p> |
---|
141 | </td> |
---|
142 | </tr> |
---|
143 | </tbody> |
---|
144 | </table> |
---|
145 | </div> |
---|
146 | </div> |
---|
147 | <table width="100%"><tr> |
---|
148 | <td align="left"><small><p>Last revised: November 03, 2006 at 19:45:40 GMT</p></small></td> |
---|
149 | <td align="right"><small>Copyright © 2001-2004 Douglas Gregor</small></td> |
---|
150 | </tr></table> |
---|
151 | <hr> |
---|
152 | <div class="spirit-nav"> |
---|
153 | <a accesskey="p" href="../id1010153-bb.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../signals.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="s05.html"><img src="../images/next.png" alt="Next"></a> |
---|
154 | </div> |
---|
155 | </body> |
---|
156 | </html> |
---|