3 moc - Katie meta object support code generator
7 moc [options] <source-file|header-file> [<source-file|header-file>] ...
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
20 Write output to file rather than stdout.
23 Add dir to the include path for header files.
26 Preprocess only; do not generate meta object code.
29 define macro, with optional definition.
35 Do not generate an #include statement.
38 Path prefix for included file.
41 Force #include, optional file name.
47 Do not display warnings.
50 Read additional options from file.
53 Display version of moc.
57 moc returns 0 on success and other on unexcepted failure.
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.
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
69 class SomeTemplate<int> : public QFrame {
73 void bugInMocDetected( int );
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.
80 =head2 Multiple inheritance requires QObject to be first.
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
86 class SomeClass : public QObject, public OtherClass {
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.
93 =head2 Function pointers cannot be arguments to signals or slots.
95 In most cases where you would consider that, we think inheritance is a
96 better alternative. Here is an example of illegal syntax:
98 class SomeClass : public QObject {
103 void apply( void (*apply)(List *, void *), void * );
106 You can work around this restriction like this:
108 typedef void (*ApplyFunctionType)( List *, void * );
110 class SomeClass : public QObject {
114 void apply( ApplyFunctionType, char * );
117 It may sometimes be even better to replace the function pointer with
118 inheritance and virtual functions, signals or slots.
120 =head2 Friend declarations cannot be placed in signals or slots sections
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:
126 class SomeClass : public QObject {
130 friend class ClassTemplate<char>; // illegal
133 =head2 Signals and slots cannot be upgraded
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:
138 class Whatever : public QButtonGroup {
141 QButtonGroup::buttonPressed; // illegal
145 The QButtonGroup::buttonPressed() slot is protected.
147 C++ quiz: What happens if you try to upgrade a protected member function
150 - All the functions are upgraded.
152 - That is not legal C++.
154 =head2 Type macros cannot be used for signal and slot arguments
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:
160 #define SIGNEDNESS(a) unsigned a
162 #define SIGNEDNESS(a) a
164 class Whatever : public QObject {
167 void someSignal( SIGNEDNESS(int) ); // illegal
170 A #define without arguments works.
172 =head2 Nested classes cannot be in the signals or slots sections nor have signals or slots
180 public slots: // illegal
191 =head2 Constructors cannot be used in signals or slots sections
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:
198 class SomeClass : public QObject {
201 SomeClass( QObject *parent, const char *name )
202 : QObject( parent, name ) {} // illegal
206 =head2 Properties need to be declared before the public section that contains
207 the respective get and set functions
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:
214 class SomeClass : public QObject {
219 Q_PROPERTY( Priority priority READ priority WRITE setPriority )
221 enum Priority { High, Low, VeryHigh, VeryLow };
222 void setPriority( Priority );
223 Priority priority() const;
227 Work around this limitation by declaring all properties at the beginning of
228 the class declaration, right after Q_OBJECT:
230 class SomeClass : public QObject {
232 Q_PROPERTY( Priority priority READ priority WRITE setPriority )
236 enum Priority { High, Low, VeryHigh, VeryLow };
237 void setPriority( Priority );
238 Priority priority() const;
246 Copyright (C) 2015 The Qt Company Ltd.
247 Copyright (C) 2016 Ivailo Monev
249 Licensed through GNU Lesser General Public License/GNU General Public License.