OSDN Git Service

33a174f252219638dffe65c0c6ebcb1e2aa10d8e
[kde/Katie.git] / src / tools / moc / moc.pod
1 =head1 NAME
2
3 moc - Katie meta object support code generator
4
5 =head1 SYNOPSIS
6
7 moc [options] <source-file|header-file> [<source-file|header-file>] ...
8
9 =head1 DESCRIPTION
10
11 moc reads one or more C++ class declarations from a C++ header or source file
12 and generates one C++ source file containing meta object information for the
13 classes. The C++ source file generated by the moc must be compiled and linked
14 with the implementation of the class (or it can be #included into the class's
15 source file).
16
17 =head1 OPTIONS
18
19     -o<file>
20         Write output to file rather than stdout.
21
22     -I<dir>
23         Add dir to the include path for header files.
24
25     -E
26         Preprocess only; do not generate meta object code.
27
28     -D<macro>[=<def>]
29         define macro, with optional definition.
30
31     -U<macro>
32         Undefine macro.
33
34     -i
35         Do not generate an #include statement.
36
37     -p<path>
38         Path prefix for included file.
39
40     -f[<file>]
41         Force #include, optional file name.
42
43     -nn
44         Do not display notes.
45
46     -nw
47         Do not display warnings.
48
49     @<file>
50         Read additional options from file.
51
52     -v
53         Display version of moc.
54
55 =head1 EXIT STATUS
56
57 moc returns 0 on success and other on unexcepted failure.
58
59 =head1 BUGS
60
61 The moc does not expand #include or #define, it simply skips any
62 preprocessor directives it encounters. This is regrettable, but is normally
63 not a problem in practice.
64
65 The moc does not handle all of C++. The main problem is that class
66 templates cannot have signals or slots. This is an important bug. Here is
67 an example:
68
69     class SomeTemplate<int> : public QFrame {
70         Q_OBJECT
71         ....
72     signals:
73         void bugInMocDetected( int );
74     };
75
76 Less importantly, the following constructs are illegal. All of them have
77 have alternatives which we think are usually better, so removing these
78 limitations is not a high priority for us.
79
80 =head2 Multiple inheritance requires QObject to be first.
81
82     If you are using multiple inheritance, moc assumes that the first inherited
83     class is a subclass of QObject. Also, be sure that only the first inherited
84     class is a QObject.
85
86         class SomeClass : public QObject, public OtherClass {
87             ...
88         };
89
90     This bug is almost impossible to fix; since the moc does not expand #include
91     or #define, it cannot find out which one of the base classes is a QObject.
92
93 =head2 Function pointers cannot be arguments to signals or slots.
94
95     In most cases where you would consider that, we think inheritance is a
96     better alternative. Here is an example of illegal syntax:
97
98         class SomeClass : public QObject {
99             Q_OBJECT
100             ...
101         public slots:
102             // illegal
103             void apply( void (*apply)(List *, void *), void * );
104         };
105
106     You can work around this restriction like this:
107
108         typedef void (*ApplyFunctionType)( List *, void * );
109
110         class SomeClass : public QObject {
111             Q_OBJECT
112             ...
113         public slots:
114             void apply( ApplyFunctionType, char * );
115         };
116
117     It  may  sometimes  be  even  better  to  replace  the function pointer with
118     inheritance and virtual functions, signals or slots.
119
120 =head2 Friend declarations cannot be placed in signals or slots sections
121
122     Sometimes it will work, but in general, friend declarations cannot be placed
123     in signals or slots sections. Put them in the good old private, protected
124     or public sections instead. Here is an example of the illegal syntax:
125
126         class SomeClass : public QObject {
127             Q_OBJECT
128             ...
129         signals:
130             friend class ClassTemplate<char>; // illegal
131         };
132
133 =head2 Signals and slots cannot be upgraded
134
135     The C++ feature of upgrading an inherited member function to public status
136     is not extended to cover signals and slots. Here is an illegal example:
137
138         class Whatever : public QButtonGroup {
139             ...
140         public slots:
141             QButtonGroup::buttonPressed; // illegal
142             ...
143         };
144
145     The QButtonGroup::buttonPressed() slot is protected.
146
147     C++ quiz: What happens if you try to upgrade a protected member function
148     which is overloaded?
149
150         - All the functions are upgraded.
151
152         - That is not legal C++.
153
154 =head2 Type macros cannot be used for signal and slot arguments
155
156     Since the moc does not expand #define, type macros that take an argument
157     will not work in signals and slots. Here is an illegal example:
158
159         #ifdef Q_OS_LINUX
160         #define SIGNEDNESS(a) unsigned a
161         #else
162         #define SIGNEDNESS(a) a
163         #endif
164         class Whatever : public QObject {
165             ...
166         signals:
167             void someSignal( SIGNEDNESS(int) ); // illegal
168         };
169
170     A #define without arguments works.
171
172 =head2  Nested  classes  cannot  be in the signals or slots sections nor have signals or slots
173
174     Here's an example:
175
176         class A {
177             Q_OBJECT
178         public:
179             class B {
180             public slots: // illegal
181                 void b();
182                 ...
183             };
184         signals:
185             class B {  // illegal
186                 void b();
187             ...
188             }:
189         };
190
191 =head2 Constructors cannot be used in signals or slots sections
192
193     It is a mystery to us why anyone would put a constructor on either the
194     signals or slots sections. You can't, anyway (except that it happens to
195     work in some cases). Put them in private, protected or public sections,
196     where they belong. Here is an example of the illegal syntax:
197
198         class SomeClass : public QObject {
199             Q_OBJECT
200         public slots:
201             SomeClass( QObject *parent, const char *name )
202                 : QObject( parent, name ) {} // illegal
203             ...
204         };
205
206 =head2  Properties need to be declared before the public section that contains
207         the respective get and set functions
208
209     Declaring the first property within or after the public section that
210     contains the type definition and the respective get and set functions does
211     not work as expected. The moc will complain that it can neither find the
212     functions nor resolve the type. Here is an example of the illegal syntax:
213
214         class SomeClass : public QObject {
215             Q_OBJECT
216         public:
217             ...
218             // illegal
219             Q_PROPERTY( Priority priority READ priority WRITE setPriority )
220             Q_ENUMS( Priority )
221             enum Priority { High, Low, VeryHigh, VeryLow };
222             void setPriority( Priority );
223             Priority priority() const;
224             ...
225         };
226
227     Work  around this limitation by declaring all properties at the beginning of
228     the class declaration, right after Q_OBJECT:
229
230         class SomeClass : public QObject {
231             Q_OBJECT
232             Q_PROPERTY( Priority priority READ priority WRITE setPriority )
233             Q_ENUMS( Priority )
234         public:
235             ...
236             enum Priority { High, Low, VeryHigh, VeryLow };
237             void setPriority( Priority );
238             Priority priority() const;
239             ...
240         };
241
242 =head1 AUTHORS
243
244 The Qt Company Ltd.
245
246 Copyright (C) 2015 The Qt Company Ltd.
247 Copyright (C) 2016 Ivailo Monev
248
249 Licensed through GNU Lesser General Public License/GNU General Public License.