Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/signals/doc/faq.xml @ 35

Last change on this file since 35 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 4.9 KB
Line 
1<?xml version="1.0" encoding="utf-8"?>
2<!--
3   Copyright (c) 2002 Douglas Gregor <doug.gregor -at- gmail.com>
4 
5   Distributed under the Boost Software License, Version 1.0.
6   (See accompanying file LICENSE_1_0.txt or copy at
7   http://www.boost.org/LICENSE_1_0.txt)
8  -->
9<!DOCTYPE section PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
10  "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
11<section last-revision="$Date: 2006/11/03 19:45:40 $">
12  <title>Frequently Asked Questions</title>
13 
14  <qandaset>
15    <qandaentry>
16      <question>
17        <para>Don't noncopyable signal semantics mean that a class
18        with a signal member will be noncopyable as well?</para>
19      </question>
20      <answer>
21        <para>No. The compiler will not be able to generate a copy
22        constructor or copy assignment operator for your class if it
23        has a signal as a member, but you are free to write your own
24        copy constructor and/or copy assignment operator. Just don't
25        try to copy the signal.</para>
26      </answer>
27    </qandaentry>
28    <qandaentry>
29      <question>
30        <para>Is Boost.Signals thread-safe?</para>
31      </question>
32      <answer>
33        <para>No. Using Boost.Signals in a multithreaded concept is
34        very dangerous, and it is very likely that the results will be
35        less than satisfying. Even trying to invoke the same signal from
36        two different threads is dangerous. Although we would like to
37        make Signals thread-safe, it is unlikely to happen without
38        help from other developers.</para>
39      </answer>
40    </qandaentry>
41    <qandaentry>
42      <question>
43        <para>How do I get Boost.Signals to work with Qt?</para>
44      </question>
45      <answer>
46        <para>When building with Qt, the Moc keywords
47        <code>signals</code> and <code>slots</code> are defined using
48        preprocessor macros, causing programs using Boost.Signals and
49        Qt together to fail to compile.</para>
50
51        <para><emphasis>For Qt 4.1 and later</emphasis>, This behavior
52        can be turned off in Qt on a per-project or per-file basis
53        with the <code>no_keywords</code> option.  This works with
54        out-of-the-box builds of Boost and Qt. You do not need to
55        re-configure, re-build, or duplicate existing libraries. For a
56        project where you want to use both Boost.Signals and Qt
57        Signals and Slots, the relevant part of your .pro file might
58        look like this:</para>
59
60        <programlisting>
61CONFIG      += no_keywords # so Qt won't #define any non-all-caps `keywords'
62INCLUDEPATH += . /usr/local/include/boost-1_33_1/
63macx:LIBS   += /usr/local/lib/libboost_signals-1_33_1.a  # ...your exact paths may vary
64</programlisting>
65
66        <para>Now you can mix Boost.Signals and Qt Signals and Slots
67        in the same files, and even within the same class or function.
68        You will have to use the upper-case versions of Qt macros in
69        your own code.  See the article <ulink
70        url="http://scottcollins.net/articles/a-deeper-look-at-signals-and-slots.html">A
71        Deeper Look at Signals and Slots</ulink> [off-site] for more
72        complete examples and a survey of the strengths of the two
73        systems.</para>
74
75        <para><emphasis>Older versions of Qt</emphasis> did not
76        provide a reliable mechanism for avoiding these unfriendly,
77        all lower-case `keyword'-like macros.  Although this is a
78        problem with Qt and not Boost.Signals, a user can use the two
79        systems together with a little extra effort. There are two
80        ways to do this:</para>
81
82        <para>The first way involves defining
83        the <code>BOOST_SIGNALS_NAMESPACE</code> 
84        macro to some other identifier (e.g., <code>signalslib</code>)
85        when building and using the Boost.Signals library. Then the
86        namespace of the Boost.Signals library will be
87        <code>boost::BOOST_SIGNALS_NAMESPACE</code> instead of
88        <code>boost::signals</code>. To retain the original namespace
89        name in translation units that do not interact with Qt, you
90        can use a namespace alias:</para>
91
92        <programlisting>
93  namespace boost {
94    namespace signals = BOOST_SIGNALS_NAMESPACE;
95  }
96</programlisting>
97
98        <para>The second way, provided by Frank Hess, involves
99        creating a header <code>signalslib.hpp</code> that contains
100          the following code:</para>
101
102        <programlisting>#ifdef signals
103#error "signalslib.hpp must be included before any qt header"
104#endif
105
106#include &lt;boost/signal.hpp&gt;
107namespace boost
108{
109  namespace signalslib = signals;
110}</programlisting>
111
112        <para>This header must be included before any Qt headers. Once
113        it has been included, you can refer to the Signals library via
114        the namespace <code>boost::signalslib</code>. This option is
115        preferable to the first option because it can be used without
116        recompiling the Signals library binary. </para>
117      </answer>
118    </qandaentry>
119  </qandaset>
120</section>
Note: See TracBrowser for help on using the repository browser.