doc/src/snippets/code/doc_src_moc.qdoc
branchRCL_3
changeset 7 3f74d0d4af4c
equal deleted inserted replaced
6:dee5afe5301f 7:3f74d0d4af4c
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the documentation of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 //! [0]
       
    43 moc_%.cpp: %.h
       
    44         moc $(DEFINES) $(INCPATH) $< -o $@
       
    45 //! [0]
       
    46 
       
    47 
       
    48 //! [1]
       
    49 moc_foo.cpp: foo.h
       
    50         moc $(DEFINES) $(INCPATH) $< -o $@
       
    51 //! [1]
       
    52 
       
    53 
       
    54 //! [2]
       
    55 foo.o: foo.moc
       
    56 
       
    57 foo.moc: foo.cpp
       
    58         moc $(DEFINES) $(INCPATH) -i $< -o $@
       
    59 //! [2]
       
    60 
       
    61 
       
    62 //! [3]
       
    63 #include "foo.moc"
       
    64 //! [3]
       
    65 
       
    66 
       
    67 //! [4]
       
    68 #ifndef Q_MOC_RUN
       
    69     ... 
       
    70 #endif
       
    71 //! [4]
       
    72 
       
    73 
       
    74 //! [5]
       
    75 class SomeTemplate<int> : public QFrame
       
    76 {
       
    77     Q_OBJECT
       
    78     ...
       
    79 
       
    80 signals:
       
    81     void mySignal(int);
       
    82 };
       
    83 //! [5]
       
    84 
       
    85 
       
    86 //! [6]
       
    87 // correct
       
    88 class SomeClass : public QObject, public OtherClass
       
    89 {
       
    90     ...
       
    91 };
       
    92 //! [6]
       
    93 
       
    94 
       
    95 //! [7]
       
    96 class SomeClass : public QObject
       
    97 {
       
    98     Q_OBJECT
       
    99 
       
   100 public slots:
       
   101     void apply(void (*apply)(List *, void *), char *); // WRONG
       
   102 };
       
   103 //! [7]
       
   104 
       
   105 
       
   106 //! [8]
       
   107 typedef void (*ApplyFunction)(List *, void *);
       
   108 
       
   109 class SomeClass : public QObject
       
   110 {
       
   111     Q_OBJECT
       
   112 
       
   113 public slots:
       
   114     void apply(ApplyFunction, char *);
       
   115 };
       
   116 //! [8]
       
   117 
       
   118 
       
   119 //! [9]
       
   120 class MyClass : public QObject
       
   121 {
       
   122     Q_OBJECT
       
   123 
       
   124     enum Error {
       
   125         ConnectionRefused,
       
   126         RemoteHostClosed,
       
   127         UnknownError
       
   128     };
       
   129 
       
   130 signals:
       
   131     void stateChanged(MyClass::Error error);
       
   132 };
       
   133 //! [9]
       
   134 
       
   135 
       
   136 //! [10]
       
   137 #ifdef ultrix
       
   138 #define SIGNEDNESS(a) unsigned a
       
   139 #else
       
   140 #define SIGNEDNESS(a) a
       
   141 #endif
       
   142 
       
   143 class Whatever : public QObject
       
   144 {
       
   145     Q_OBJECT
       
   146 
       
   147 signals:
       
   148     void someSignal(SIGNEDNESS(int));
       
   149 };
       
   150 //! [10]
       
   151 
       
   152 
       
   153 //! [11]
       
   154 class A
       
   155 {
       
   156 public:
       
   157     class B
       
   158     {
       
   159         Q_OBJECT
       
   160 
       
   161     public slots:   // WRONG
       
   162         void b();
       
   163     };
       
   164 };
       
   165 //! [11]