@@ -4,15 +4,22 @@ It is possible to use libsigc++ with Qt. However, because of the signals/slots
4
4
mechanism of Qt, there is some setup that must be done in order for this to
5
5
happen correctly.
6
6
7
+ The official Qt documentation may be found here: https://doc.qt.io/qt-5/signalsandslots.html#using-qt-with-3rd-party-signals-and-slots
8
+
7
9
Steps to use libsigc++ with Qt:
8
10
1 . In your .pro file, add ` CONFIG += no_keywords ` . This configures Qt to not
9
- define the keywords ` emit ` , ` signals ` , and ` slot ` .
11
+ define the macros ` emit ` , ` signals ` , and ` slot ` . These are keywords for moc,
12
+ which preprocesses the source files in order to use Qt signals/slots.
10
13
2 . In your header files, change the ` signals: ` section of your class to instead
11
14
be ` Q_SIGNALS `
12
15
3 . In your header files, change the ` public slots: ` section of your class to
13
16
instead be ` public Q_SLOTS: `
14
17
4 . In any class that you emit a signal, change ` emit ` to be ` Q_EMIT ` .
15
18
19
+ In general, using the Q\_ macros is a good idea if your code is a library
20
+ intended to be used by people other than yourself, as they may be using
21
+ code(e.g. libsigc++/boost signals) that will conflict with Qt(moc) keywords.
22
+
16
23
Here's an example of a class before and after this conversion(note: irrelevant
17
24
code has been removed):
18
25
@@ -43,3 +50,18 @@ public Q_SLOTS:
43
50
Since libsigc++ simply requires a slot to be a function, you can call Qt
44
51
slots easily using libsigc++. Similarly, a function that is a libsigc++ slot
45
52
can also be used as a Qt slot.
53
+
54
+ # Other Build Systems
55
+ If you are not using qmake to build your Qt project, you must tell your
56
+ buildsystem to define ` QT_NO_KEYWORDS ` . If you're using CMake, this may
57
+ be done like the following:
58
+
59
+ ```
60
+ add_definitions(-DQT_NO_KEYWORDS)
61
+ ```
62
+
63
+ or in a more modern CMake way:
64
+
65
+ ```
66
+ target_compile_definitions(some_target PRIVATE QT_NO_KEYWORDS)
67
+ ```
0 commit comments