1 .TH moc 1 "24 June 2001" "Nokia Corporation and/or its subsidiary(-ies)" \" -*- nroff -*-
3 .\" Copyright (C) 2015 The Qt Company Ltd.
4 .\" Contact: http://www.qt.io/licensing/
6 .\" This file is part of the QtGui module of the Qt Toolkit.
8 .\" $QT_BEGIN_LICENSE:LGPL$
9 .\" Commercial License Usage
10 .\" Licensees holding valid commercial Qt licenses may use this file in
11 .\" accordance with the commercial license agreement provided with the
12 .\" Software or, alternatively, in accordance with the terms contained in
13 .\" a written agreement between you and The Qt Company. For licensing terms
14 .\" and conditions see http://www.qt.io/terms-conditions. For further
15 .\" information use the contact form at http://www.qt.io/contact-us.
17 .\" GNU Lesser General Public License Usage
18 .\" Alternatively, this file may be used under the terms of the GNU Lesser
19 .\" General Public License version 2.1 as published by the Free Software
20 .\" Foundation and appearing in the file LICENSE.LGPL included in the
21 .\" packaging of this file. Please review the following information to
22 .\" ensure the GNU Lesser General Public License version 2.1 requirements
23 .\" will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 .\" As a special exception, The Qt Company gives you certain additional
26 .\" rights. These rights are described in The Qt Company LGPL Exception
27 .\" version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 .\" GNU General Public License Usage
30 .\" Alternatively, this file may be used under the terms of the GNU
31 .\" General Public License version 3.0 as published by the Free Software
32 .\" Foundation and appearing in the file LICENSE.GPL included in the
33 .\" packaging of this file. Please review the following information to
34 .\" ensure the GNU General Public License version 3.0 requirements will be
35 .\" met: http://www.gnu.org/copyleft/gpl.html.
42 moc \- generate Qt meta object support code
45 [\-o file] [\-i] [\-f] [\-k] [\-ldbg] [\-nw] [\-p path] [\-q path] [\-v] file
47 This page documents the
48 .B Meta Object Compiler
49 for the Qt GUI application framework. The
51 reads one or more C++ class declarations from a C++ header or source
52 file and generates one C++ source file containing meta object
53 information for the classes. The C++ source file generated by the
55 must be compiled and linked with the implementation of the class (or it
56 can be #included into the class's source file).
60 to create your Makefiles, build rules will be included that call the
62 when required, so you will not need to use the
66 In brief, the meta object system is a structure used by Qt (see
67 .BR http://doc.trolltech.com ")"
68 for component programming and run time type information. It adds
69 properties and inheritance information to (some) classes and
70 provides a new type of communication between those instances of those
78 rather than to stdout.
81 Force the generation of an #include statement in the output.
82 This is the default for files whose name matches the regular
83 expression .[hH][^.]* (i.e. the extension starts with
88 option is only useful if you have header files that do not follow the
89 standard naming conventions.
92 Do not generate an #include statement in the output. This may be used
95 on a C++ file containing one or more class declarations. You should then
96 #include the meta object code in the .cpp file (see USAGE below). If both
100 are present, the last one wins.
103 Do not generate any warnings. Not recommended.
106 Write a flood of lex debug information to stdout.
113 to the file name in the generated #include statement (if one is generated).
120 to the file name of qt #include files in the generated code.
123 Displays the version of
127 You can explicitly tell the
129 not to parse parts of a header
130 file. It recognizes any C++ comment (//) that contains the substrings
131 MOC_SKIP_BEGIN or MOC_SKIP_END. They work as you would expect and you
132 can have several levels of them. The net result as seen by the
134 is as if you had removed all lines between a MOC_SKIP_BEGIN and a
138 is almost always invoked by
143 is typically used with an input file containing class declarations
148 class YourClass : public QObject {
154 YourClass( QObject * parent=0, const char * name=0 );
165 Here is a useful makefile rule if you only use GNU make:
174 If you want to write portably, you can use individual rules of the
184 You must also remember to add
186 to your SOURCES (substitute your favorite name) variable and
188 to your OBJECTS variable.
190 (While we prefer to name our C++ source files .cpp, the
192 doesn't know that, so you can use .C, .cc, .CC, .cxx or even .c++ if
195 If you have class declarations in C++ files, we recommend that you use
196 a makefile rule like this:
220 where all the classes declared in that file are fully known.
222 Sometimes you may get linkage errors, saying that
223 YourClass::className() is undefined or that YourClass lacks a vtbl.
224 Those errors happen most often when you forget to compile the
225 moc-generated C++ code or include that object file in the link
230 will warn you about a number of dangerous or illegal constructs.
235 does not expand #include or #define, it simply skips any preprocessor
236 directives it encounters. This is regrettable, but is normally not a
241 does not handle all of C++. The main problem is that class templates
242 cannot have signals or slots. This is an important bug. Here is an
247 class SomeTemplate<int> : public QFrame {
251 void bugInMocDetected( int );
256 Less importantly, the following constructs are illegal. All of them
257 have have alternatives which we think are usually better, so removing
258 these limitations is not a high priority for us.
259 .SS "Multiple inheritance requires QObject to be first."
260 If you are using multiple inheritance,
264 inherited class is a subclass of QObject. Also, be sure that
266 the first inherited class is a QObject.
270 class SomeClass : public QObject, public OtherClass {
276 This bug is almost impossible to fix; since the
279 #include or #define, it cannot find out which one of the base classes is a
281 .SS "Function pointers cannot be arguments to signals or slots."
282 In most cases where you would consider that, we think inheritance is a
283 better alternative. Here is an example of illegal syntax:
287 class SomeClass : public QObject {
292 void apply( void (*apply)(List *, void *), void * );
297 You can work around this restriction like this:
301 typedef void (*ApplyFunctionType)( List *, void * );
303 class SomeClass : public QObject {
307 void apply( ApplyFunctionType, char * );
312 It may sometimes be even better to replace the function pointer with
313 inheritance and virtual functions, signals or slots.
314 .SS "Friend declarations cannot be placed in signals or slots sections"
315 Sometimes it will work, but in general, friend declarations cannot be
320 sections. Put them in the good old
321 .BR private ", " protected
324 sections instead. Here is an example of the illegal syntax:
328 class SomeClass : public QObject {
332 friend class ClassTemplate<char>; // illegal
336 .SS "Signals and slots cannot be upgraded"
337 The C++ feature of upgrading an inherited member function to
339 status is not extended to cover signals and slots. Here is an illegal
344 class Whatever : public QButtonGroup {
347 QButtonGroup::buttonPressed; // illegal
353 The QButtonGroup::buttonPressed() slot is protected.
355 C++ quiz: What happens if you try to upgrade a protected member
356 function which is overloaded?
358 - All the functions are upgraded.
360 - That is not legal C++.
361 .\" Good idea, but look in the SEE ALSO section...
362 .SS "Type macros cannot be used for signal and slot arguments"
366 does not expand #define, type macros that take an argument
367 will not work in signals and slots. Here is an illegal example:
372 #define SIGNEDNESS(a) unsigned a
374 #define SIGNEDNESS(a) a
376 class Whatever : public QObject {
379 void someSignal( SIGNEDNESS(int) ); // illegal
382 A #define without arguments works.
385 .SS "Nested classes cannot be in the signals or slots sections nor have signals or slots"
394 public slots: // illegal
407 .SS "Constructors cannot be used in signals or slots sections"
408 It is a mystery to us why anyone would put a constructor on either the
412 sections. You can't, anyway (except that it happens to work in some
414 .BR private ", " protected
417 sections, where they belong. Here is an example of the illegal syntax:
421 class SomeClass : public QObject {
424 SomeClass( QObject *parent, const char *name )
425 : QObject( parent, name ) {} // illegal
430 .SS "Properties need to be declared before the public section that contains the respective get and set functions"
432 Declaring the first property within or after the public section that
433 contains the type definition and the respective get and set functions
434 does not work as expected. The
436 will complain that it can neither
437 find the functions nor resolve the type. Here is an example of the
442 class SomeClass : public QObject {
447 Q_PROPERTY( Priority priority READ priority WRITE setPriority )
449 enum Priority { High, Low, VeryHigh, VeryLow };
450 void setPriority( Priority );
451 Priority priority() const;
457 Work around this limitation by declaring all properties at the
458 beginning of the class declaration, right after Q_OBJECT:
462 class SomeClass : public QObject {
464 Q_PROPERTY( Priority priority READ priority WRITE setPriority )
468 enum Priority { High, Low, VeryHigh, VeryLow };
469 void setPriority( Priority );
470 Priority priority() const;
477 .BR http://www.trolltech.com ", "
478 .BR "C++ ARM, section r.11.3" " (for the answer to the quiz), and"
479 .BR http://doc.trolltech.com " (for complete Qt documentation)."