Qt 4.8
qobjectdefs.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
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.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
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.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QOBJECTDEFS_H
43 #define QOBJECTDEFS_H
44 
45 #include <QtCore/qnamespace.h>
46 
48 
50 
51 QT_MODULE(Core)
52 
53 class QByteArray;
54 
55 class QString;
56 
57 #ifndef Q_MOC_OUTPUT_REVISION
58 #define Q_MOC_OUTPUT_REVISION 63
59 #endif
60 
61 // The following macros are our "extensions" to C++
62 // They are used, strictly speaking, only by the moc.
63 
64 #ifndef Q_MOC_RUN
65 # if defined(QT_NO_KEYWORDS)
66 # define QT_NO_EMIT
67 # else
68 # define slots
69 # define signals protected
70 # endif
71 # define Q_SLOTS
72 # define Q_SIGNALS protected
73 # define Q_PRIVATE_SLOT(d, signature)
74 # define Q_EMIT
75 #ifndef QT_NO_EMIT
76 # define emit
77 #endif
78 #define Q_CLASSINFO(name, value)
79 #define Q_INTERFACES(x)
80 #define text)
81 #define Q_PRIVATE_PROPERTY(d,;
82 #define Q_REVISION(v)
83 #define Q_OVERRIDE(text)
84 #define Q_ENUMS(x)
85 #define Q_FLAGS(x)
86 #ifdef QT3_SUPPORT
87 # define Q_SETS(x)
88 #endif
89 #define Q_SCRIPTABLE
90 #define Q_INVOKABLE
91 #define Q_SIGNAL
92 #define Q_SLOT
93 
94 #ifndef QT_NO_TRANSLATION
95 # ifndef QT_NO_TEXTCODEC
96 // full set of tr functions
97 // ### Qt 5: merge overloads
98 # define QT_TR_FUNCTIONS \
99  static inline QString tr(const char *s, const char *c = 0) \
100  { return staticMetaObject.tr(s, c); } \
101  static inline QString trUtf8(const char *s, const char *c = 0) \
102  { return staticMetaObject.trUtf8(s, c); } \
103  static inline QString tr(const char *s, const char *c, int n) \
104  { return staticMetaObject.tr(s, c, n); } \
105  static inline QString trUtf8(const char *s, const char *c, int n) \
106  { return staticMetaObject.trUtf8(s, c, n); }
107 # else
108 // no QTextCodec, no utf8
109 // ### Qt 5: merge overloads
110 # define QT_TR_FUNCTIONS \
111  static inline QString tr(const char *s, const char *c = 0) \
112  { return staticMetaObject.tr(s, c); } \
113  static inline QString tr(const char *s, const char *c, int n) \
114  { return staticMetaObject.tr(s, c, n); }
115 # endif
116 #else
117 // inherit the ones from QObject
118 # define QT_TR_FUNCTIONS
119 #endif
120 
121 #if defined(QT_NO_QOBJECT_CHECK)
122 /* tmake ignore Q_OBJECT */
123 #define Q_OBJECT_CHECK
124 #else
125 
126 /* This is a compile time check that ensures that any class cast with qobject_cast
127  actually contains a Q_OBJECT macro. Note: qobject_cast will fail if a QObject
128  subclass doesn't contain Q_OBJECT.
129 
130  In qt_check_for_QOBJECT_macro, we call a dummy templated function with two
131  parameters, the first being "this" and the other the target of the qobject
132  cast. If the types are not identical, we know that a Q_OBJECT macro is missing.
133 
134  If you get a compiler error here, make sure that the class you are casting
135  to contains a Q_OBJECT macro.
136 */
137 
138 /* tmake ignore Q_OBJECT */
139 #define Q_OBJECT_CHECK \
140  template <typename T> inline void qt_check_for_QOBJECT_macro(const T &_q_argument) const \
141  { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; }
142 
143 template <typename T>
144 inline int qYouForgotTheQ_OBJECT_Macro(T, T) { return 0; }
145 
146 template <typename T1, typename T2>
147 inline void qYouForgotTheQ_OBJECT_Macro(T1, T2) {}
148 #endif // QT_NO_QOBJECT_CHECK
149 
150 #ifdef Q_NO_DATA_RELOCATION
151 #define Q_OBJECT_GETSTATICMETAOBJECT static const QMetaObject &getStaticMetaObject();
152 #else
153 #define Q_OBJECT_GETSTATICMETAOBJECT
154 #endif
155 
156 /* tmake ignore Q_OBJECT */
157 #define Q_OBJECT \
158 public: \
159  Q_OBJECT_CHECK \
160  static const QMetaObject staticMetaObject; \
161  Q_OBJECT_GETSTATICMETAOBJECT \
162  virtual const QMetaObject *metaObject() const; \
163  virtual void *qt_metacast(const char *); \
164  QT_TR_FUNCTIONS \
165  virtual int qt_metacall(QMetaObject::Call, int, void **); \
166 private: \
167  Q_DECL_HIDDEN static const QMetaObjectExtraData staticMetaObjectExtraData; \
168  Q_DECL_HIDDEN static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **);
169 
170 /* tmake ignore Q_OBJECT */
171 #define Q_OBJECT_FAKE Q_OBJECT
172 /* tmake ignore Q_GADGET */
173 #define Q_GADGET \
174 public: \
175  static const QMetaObject staticMetaObject; \
176  Q_OBJECT_GETSTATICMETAOBJECT \
177 private:
178 #else // Q_MOC_RUN
179 #define slots slots
180 #define signals signals
181 #define Q_SLOTS Q_SLOTS
182 #define Q_SIGNALS Q_SIGNALS
183 #define Q_CLASSINFO(name, value) Q_CLASSINFO(name, value)
184 #define Q_INTERFACES(x) Q_INTERFACES(x)
185 #define text) Q_PROPERTY(text)
186 #define; Q_PRIVATE_PROPERTY(d, text)
187 #define Q_REVISION(v) Q_REVISION(v)
188 #define Q_OVERRIDE(text) Q_OVERRIDE(text)
189 #define Q_ENUMS(x) Q_ENUMS(x)
190 #define Q_FLAGS(x) Q_FLAGS(x)
191 #ifdef QT3_SUPPORT
192 # define Q_SETS(x) Q_SETS(x)
193 #endif
194  /* tmake ignore Q_OBJECT */
195 #define Q_OBJECT Q_OBJECT
196  /* tmake ignore Q_OBJECT */
197 #define Q_OBJECT_FAKE Q_OBJECT_FAKE
198  /* tmake ignore Q_GADGET */
199 #define Q_GADGET Q_GADGET
200 #define Q_SCRIPTABLE Q_SCRIPTABLE
201 #define Q_INVOKABLE Q_INVOKABLE
202 #define Q_SIGNAL Q_SIGNAL
203 #define Q_SLOT Q_SLOT
204 #endif //Q_MOC_RUN
205 
206 // macro for onaming members
207 #ifdef METHOD
208 #undef METHOD
209 #endif
210 #ifdef SLOT
211 #undef SLOT
212 #endif
213 #ifdef SIGNAL
214 #undef SIGNAL
215 #endif
216 
217 Q_CORE_EXPORT const char *qFlagLocation(const char *method);
218 
219 #define QTOSTRING_HELPER(s) #s
220 #define QTOSTRING(s) QTOSTRING_HELPER(s)
221 #ifndef QT_NO_DEBUG
222 # define QLOCATION "\0" __FILE__ ":" QTOSTRING(__LINE__)
223 # ifndef QT_NO_KEYWORDS
224 # define METHOD(a) qFlagLocation("0"#a QLOCATION)
225 # endif
226 # define SLOT(a) qFlagLocation("1"#a QLOCATION)
227 # define SIGNAL(a) qFlagLocation("2"#a QLOCATION)
228 #else
229 # ifndef QT_NO_KEYWORDS
230 # define METHOD(a) "0"#a
231 # endif
232 # define SLOT(a) "1"#a
233 # define SIGNAL(a) "2"#a
234 #endif
235 
236 #ifdef QT3_SUPPORT
237 #define METHOD_CODE 0 // member type codes
238 #define SLOT_CODE 1
239 #define SIGNAL_CODE 2
240 #endif
241 
242 #define QMETHOD_CODE 0 // member type codes
243 #define QSLOT_CODE 1
244 #define QSIGNAL_CODE 2
245 
246 #define Q_ARG(type, data) QArgument<type >(#type, data)
247 #define Q_RETURN_ARG(type, data) QReturnArgument<type >(#type, data)
248 
249 class QObject;
250 class QMetaMethod;
251 class QMetaEnum;
252 class QMetaProperty;
253 class QMetaClassInfo;
254 
255 
257 {
258 public:
259  inline QGenericArgument(const char *aName = 0, const void *aData = 0)
260  : _data(aData), _name(aName) {}
261  inline void *data() const { return const_cast<void *>(_data); }
262  inline const char *name() const { return _name; }
263 
264 private:
265  const void *_data;
266  const char *_name;
267 };
268 
270 {
271 public:
272  inline QGenericReturnArgument(const char *aName = 0, void *aData = 0)
273  : QGenericArgument(aName, aData)
274  {}
275 };
276 
277 template <class T>
279 {
280 public:
281  inline QArgument(const char *aName, const T &aData)
282  : QGenericArgument(aName, static_cast<const void *>(&aData))
283  {}
284 };
285 template <class T>
286 class QArgument<T &>: public QGenericArgument
287 {
288 public:
289  inline QArgument(const char *aName, T &aData)
290  : QGenericArgument(aName, static_cast<const void *>(&aData))
291  {}
292 };
293 
294 
295 template <typename T>
297 {
298 public:
299  inline QReturnArgument(const char *aName, T &aData)
300  : QGenericReturnArgument(aName, static_cast<void *>(&aData))
301  {}
302 };
303 
305 {
306  const char *className() const;
307  const QMetaObject *superClass() const;
308 
309  QObject *cast(QObject *obj) const;
310  const QObject *cast(const QObject *obj) const;
311 
312 #ifndef QT_NO_TRANSLATION
313  // ### Qt 4: Merge overloads
314  QString tr(const char *s, const char *c) const;
315  QString trUtf8(const char *s, const char *c) const;
316  QString tr(const char *s, const char *c, int n) const;
317  QString trUtf8(const char *s, const char *c, int n) const;
318 #endif // QT_NO_TRANSLATION
319 
320  int methodOffset() const;
321  int enumeratorOffset() const;
322  int propertyOffset() const;
323  int classInfoOffset() const;
324 
325  int constructorCount() const;
326  int methodCount() const;
327  int enumeratorCount() const;
328  int propertyCount() const;
329  int classInfoCount() const;
330 
331  int indexOfConstructor(const char *constructor) const;
332  int indexOfMethod(const char *method) const;
333  int indexOfSignal(const char *signal) const;
334  int indexOfSlot(const char *slot) const;
335  int indexOfEnumerator(const char *name) const;
336  int indexOfProperty(const char *name) const;
337  int indexOfClassInfo(const char *name) const;
338 
339  QMetaMethod constructor(int index) const;
340  QMetaMethod method(int index) const;
341  QMetaEnum enumerator(int index) const;
342  QMetaProperty property(int index) const;
343  QMetaClassInfo classInfo(int index) const;
344  QMetaProperty userProperty() const;
345 
346  static bool checkConnectArgs(const char *signal, const char *method);
347  static QByteArray normalizedSignature(const char *method);
348  static QByteArray normalizedType(const char *type);
349 
350  // internal index-based connect
351  static bool connect(const QObject *sender, int signal_index,
352  const QObject *receiver, int method_index,
353  int type = 0, int *types = 0);
354  // internal index-based disconnect
355  static bool disconnect(const QObject *sender, int signal_index,
356  const QObject *receiver, int method_index);
357  static bool disconnectOne(const QObject *sender, int signal_index,
358  const QObject *receiver, int method_index);
359  // internal slot-name based connect
360  static void connectSlotsByName(QObject *o);
361 
362  // internal index-based signal activation
363  static void activate(QObject *sender, int signal_index, void **argv); //obsolete
364  static void activate(QObject *sender, int from_signal_index, int to_signal_index, void **argv); //obsolete
365  static void activate(QObject *sender, const QMetaObject *, int local_signal_index, void **argv);
366  static void activate(QObject *sender, const QMetaObject *, int from_local_signal_index, int to_local_signal_index, void **argv); //obsolete
367 
368  // internal guarded pointers
369  static void addGuard(QObject **ptr);
370  static void removeGuard(QObject **ptr);
371  static void changeGuard(QObject **ptr, QObject *o);
372 
373  static bool invokeMethod(QObject *obj, const char *member,
386 
387  static inline bool invokeMethod(QObject *obj, const char *member,
399  {
400  return invokeMethod(obj, member, Qt::AutoConnection, ret, val0, val1, val2, val3,
401  val4, val5, val6, val7, val8, val9);
402  }
403 
404  static inline bool invokeMethod(QObject *obj, const char *member,
405  Qt::ConnectionType type,
416  {
417  return invokeMethod(obj, member, type, QGenericReturnArgument(), val0, val1, val2,
418  val3, val4, val5, val6, val7, val8, val9);
419  }
420 
421  static inline bool invokeMethod(QObject *obj, const char *member,
432  {
433  return invokeMethod(obj, member, Qt::AutoConnection, QGenericReturnArgument(), val0,
434  val1, val2, val3, val4, val5, val6, val7, val8, val9);
435  }
436 
437  QObject *newInstance(QGenericArgument val0 = QGenericArgument(0),
446  QGenericArgument val9 = QGenericArgument()) const;
447 
448  enum Call {
458  CreateInstance
459  };
460 
461  int static_metacall(Call, int, void **) const;
462  static int metacall(QObject *, Call, int, void **);
463 
464 #ifdef QT3_SUPPORT
465  QT3_SUPPORT const char *superClassName() const;
466 #endif
467 
468  struct { // private data
470  const char *stringdata;
471  const uint *data;
472  const void *extradata;
473  } d;
474 };
475 
476 typedef const QMetaObject& (*QMetaObjectAccessor)();
477 
479 {
480 #ifdef Q_NO_DATA_RELOCATION
481  const QMetaObjectAccessor *objects;
482 #else
484 #endif
485 
486  typedef void (*StaticMetacallFunction)(QObject *, QMetaObject::Call, int, void **); //from revision 6
487  //typedef int (*StaticMetaCall)(QMetaObject::Call, int, void **); //used from revison 2 until revison 5
488  StaticMetacallFunction static_metacall;
489 };
490 
491 inline const char *QMetaObject::className() const
492 { return d.stringdata; }
493 
495 { return d.superdata; }
496 
497 #ifdef QT3_SUPPORT
498 inline const char *QMetaObject::superClassName() const
499 { return d.superdata ? d.superdata->className() : 0; }
500 #endif
501 
503 
505 
506 #endif // QOBJECTDEFS_H
double d
Definition: qnumeric_p.h:62
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
QArgument(const char *aName, const T &aData)
Definition: qobjectdefs.h:281
int type
Definition: qmetatype.cpp:239
unsigned char c[8]
Definition: qnumeric_p.h:62
The QMetaEnum class provides meta-data about an enumerator.
Definition: qmetaobject.h:147
const void * extradata
Definition: qobjectdefs.h:472
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void * data() const
Returns the data set in the constructor.
Definition: qobjectdefs.h:261
#define QT_MODULE(x)
Definition: qglobal.h:2783
static void invokeMethod(QObject *obj, const char *methodName)
Definition: qtestcase.cpp:979
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int qYouForgotTheQ_OBJECT_Macro(T, T)
Definition: qobjectdefs.h:144
const void * _data
Definition: qobjectdefs.h:265
The QString class provides a Unicode character string.
Definition: qstring.h:83
const char * stringdata
Definition: qobjectdefs.h:470
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
The QGenericReturnArgument class is an internal helper class for marshalling arguments.
Definition: qobjectdefs.h:269
const QMetaObject &(* QMetaObjectAccessor)()
Definition: qobjectdefs.h:476
const char * className
Definition: qwizard.cpp:137
The QGenericArgument class is an internal helper class for marshalling arguments. ...
Definition: qobjectdefs.h:256
ConnectionType
Definition: qnamespace.h:1469
QArgument(const char *aName, T &aData)
Definition: qobjectdefs.h:289
static bool invokeMethod(QObject *obj, const char *member, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Definition: qobjectdefs.h:387
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static bool invokeMethod(QObject *obj, const char *member, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Definition: qobjectdefs.h:421
const char * name
unsigned int uint
Definition: qglobal.h:996
const T * ptr(const T &t)
Q_CORE_EXPORT const char * qFlagLocation(const char *method)
Definition: qobject.cpp:2222
QGenericReturnArgument(const char *aName=0, void *aData=0)
Constructs a QGenericReturnArgument object with the given name and data.
Definition: qobjectdefs.h:272
const uint * data
Definition: qobjectdefs.h:471
const QMetaObject * superClass() const
Returns the meta-object of the superclass, or 0 if there is no such object.
Definition: qobjectdefs.h:494
QReturnArgument(const char *aName, T &aData)
Definition: qobjectdefs.h:299
StaticMetacallFunction static_metacall
Definition: qobjectdefs.h:488
const char * _name
Definition: qobjectdefs.h:266
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
static const struct @32 types[]
The QMetaClassInfo class provides additional information about a class.
Definition: qmetaobject.h:224
const QMetaObject * superdata
Definition: qobjectdefs.h:469
QGenericArgument(const char *aName=0, const void *aData=0)
Constructs a QGenericArgument object with the given name and data.
Definition: qobjectdefs.h:259
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
const char * property
Definition: qwizard.cpp:138
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType type, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Definition: qobjectdefs.h:404
quint16 index
The QMetaProperty class provides meta-data about a property.
Definition: qmetaobject.h:176
#define QT_END_HEADER
Definition: qglobal.h:137
const QMetaObject ** objects
Definition: qobjectdefs.h:483
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
const char * name() const
Returns the name set in the constructor.
Definition: qobjectdefs.h:262