1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Copyright (C) 2016 Intel Corporation.
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the QtCore module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#ifndef QOBJECTDEFS_H
42#define QOBJECTDEFS_H
43
44#if defined(__OBJC__) && !defined(__cplusplus)
45# warning "File built in Objective-C mode (.m), but using Qt requires Objective-C++ (.mm)"
46#endif
47
48#include <QtCore/qnamespace.h>
49
50#include <QtCore/qobjectdefs_impl.h>
51
52QT_BEGIN_NAMESPACE
53
54
55class QByteArray;
56struct QArrayData;
57typedef QArrayData QByteArrayData;
58
59class QString;
60#ifndef Q_MOC_OUTPUT_REVISION
61#define Q_MOC_OUTPUT_REVISION 67
62#endif
63
64// The following macros can be defined by tools that understand Qt
65// to have the information from the macro.
66#ifndef QT_ANNOTATE_CLASS
67# ifndef Q_COMPILER_VARIADIC_MACROS
68# define QT_ANNOTATE_CLASS(type, x)
69# else
70# define QT_ANNOTATE_CLASS(type, ...)
71# endif
72#endif
73#ifndef QT_ANNOTATE_CLASS2
74# define QT_ANNOTATE_CLASS2(type, a1, a2)
75#endif
76#ifndef QT_ANNOTATE_FUNCTION
77# define QT_ANNOTATE_FUNCTION(x)
78#endif
79#ifndef QT_ANNOTATE_ACCESS_SPECIFIER
80# define QT_ANNOTATE_ACCESS_SPECIFIER(x)
81#endif
82
83// The following macros are our "extensions" to C++
84// They are used, strictly speaking, only by the moc.
85
86#ifndef Q_MOC_RUN
87#ifndef QT_NO_META_MACROS
88# if defined(QT_NO_KEYWORDS)
89# define QT_NO_EMIT
90# else
91# ifndef QT_NO_SIGNALS_SLOTS_KEYWORDS
92# define slots Q_SLOTS
93# define signals Q_SIGNALS
94# endif
95# endif
96# define Q_SLOTS QT_ANNOTATE_ACCESS_SPECIFIER(qt_slot)
97# define Q_SIGNALS public QT_ANNOTATE_ACCESS_SPECIFIER(qt_signal)
98# define Q_PRIVATE_SLOT(d, signature) QT_ANNOTATE_CLASS2(qt_private_slot, d, signature)
99# define Q_EMIT
100#ifndef QT_NO_EMIT
101# define emit
102#endif
103#ifndef Q_CLASSINFO
104# define Q_CLASSINFO(name, value)
105#endif
106#define Q_PLUGIN_METADATA(x) QT_ANNOTATE_CLASS(qt_plugin_metadata, x)
107#define Q_INTERFACES(x) QT_ANNOTATE_CLASS(qt_interfaces, x)
108#ifdef Q_COMPILER_VARIADIC_MACROS
109# define Q_PROPERTY(...) QT_ANNOTATE_CLASS(qt_property, __VA_ARGS__)
110#else
111# define Q_PROPERTY(text) QT_ANNOTATE_CLASS(qt_property, text)
112#endif
113#define Q_PRIVATE_PROPERTY(d, text) QT_ANNOTATE_CLASS2(qt_private_property, d, text)
114#ifndef Q_REVISION
115# define Q_REVISION(v)
116#endif
117#define Q_OVERRIDE(text) QT_ANNOTATE_CLASS(qt_override, text)
118#define QDOC_PROPERTY(text) QT_ANNOTATE_CLASS(qt_qdoc_property, text)
119#define Q_ENUMS(x) QT_ANNOTATE_CLASS(qt_enums, x)
120#define Q_FLAGS(x) QT_ANNOTATE_CLASS(qt_enums, x)
121#define Q_ENUM_IMPL(ENUM) \
122 friend Q_DECL_CONSTEXPR const QMetaObject *qt_getEnumMetaObject(ENUM) Q_DECL_NOEXCEPT { return &staticMetaObject; } \
123 friend Q_DECL_CONSTEXPR const char *qt_getEnumName(ENUM) Q_DECL_NOEXCEPT { return #ENUM; }
124#define Q_ENUM(x) Q_ENUMS(x) Q_ENUM_IMPL(x)
125#define Q_FLAG(x) Q_FLAGS(x) Q_ENUM_IMPL(x)
126#define Q_ENUM_NS_IMPL(ENUM) \
127 inline Q_DECL_CONSTEXPR const QMetaObject *qt_getEnumMetaObject(ENUM) Q_DECL_NOEXCEPT { return &staticMetaObject; } \
128 inline Q_DECL_CONSTEXPR const char *qt_getEnumName(ENUM) Q_DECL_NOEXCEPT { return #ENUM; }
129#define Q_ENUM_NS(x) Q_ENUMS(x) Q_ENUM_NS_IMPL(x)
130#define Q_FLAG_NS(x) Q_FLAGS(x) Q_ENUM_NS_IMPL(x)
131#define Q_SCRIPTABLE QT_ANNOTATE_FUNCTION(qt_scriptable)
132#define Q_INVOKABLE QT_ANNOTATE_FUNCTION(qt_invokable)
133#define Q_SIGNAL QT_ANNOTATE_FUNCTION(qt_signal)
134#define Q_SLOT QT_ANNOTATE_FUNCTION(qt_slot)
135#endif // QT_NO_META_MACROS
136
137#ifndef QT_NO_TRANSLATION
138// full set of tr functions
139# define QT_TR_FUNCTIONS \
140 static inline QString tr(const char *s, const char *c = Q_NULLPTR, int n = -1) \
141 { return staticMetaObject.tr(s, c, n); } \
142 QT_DEPRECATED static inline QString trUtf8(const char *s, const char *c = Q_NULLPTR, int n = -1) \
143 { return staticMetaObject.tr(s, c, n); }
144#else
145// inherit the ones from QObject
146# define QT_TR_FUNCTIONS
147#endif
148
149// ### Qt6: remove
150#define Q_OBJECT_CHECK /* empty, unused since Qt 5.2 */
151
152#if defined(Q_CC_INTEL)
153// Cannot redefine the visibility of a method in an exported class
154# define Q_DECL_HIDDEN_STATIC_METACALL
155#else
156# define Q_DECL_HIDDEN_STATIC_METACALL Q_DECL_HIDDEN
157#endif
158
159#if defined(Q_CC_CLANG) && Q_CC_CLANG >= 306
160# define Q_OBJECT_NO_OVERRIDE_WARNING QT_WARNING_DISABLE_CLANG("-Winconsistent-missing-override")
161#elif defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && Q_CC_GNU >= 501
162# define Q_OBJECT_NO_OVERRIDE_WARNING QT_WARNING_DISABLE_GCC("-Wsuggest-override")
163#else
164# define Q_OBJECT_NO_OVERRIDE_WARNING
165#endif
166
167#if defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && Q_CC_GNU >= 600
168# define Q_OBJECT_NO_ATTRIBUTES_WARNING QT_WARNING_DISABLE_GCC("-Wattributes")
169#else
170# define Q_OBJECT_NO_ATTRIBUTES_WARNING
171#endif
172
173/* qmake ignore Q_OBJECT */
174#define Q_OBJECT \
175public: \
176 QT_WARNING_PUSH \
177 Q_OBJECT_NO_OVERRIDE_WARNING \
178 static const QMetaObject staticMetaObject; \
179 virtual const QMetaObject *metaObject() const; \
180 virtual void *qt_metacast(const char *); \
181 virtual int qt_metacall(QMetaObject::Call, int, void **); \
182 QT_TR_FUNCTIONS \
183private: \
184 Q_OBJECT_NO_ATTRIBUTES_WARNING \
185 Q_DECL_HIDDEN_STATIC_METACALL static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); \
186 QT_WARNING_POP \
187 struct QPrivateSignal {}; \
188 QT_ANNOTATE_CLASS(qt_qobject, "")
189
190/* qmake ignore Q_OBJECT */
191#define Q_OBJECT_FAKE Q_OBJECT QT_ANNOTATE_CLASS(qt_fake, "")
192
193#ifndef QT_NO_META_MACROS
194/* qmake ignore Q_GADGET */
195#define Q_GADGET \
196public: \
197 static const QMetaObject staticMetaObject; \
198 void qt_check_for_QGADGET_macro(); \
199 typedef void QtGadgetHelper; \
200private: \
201 QT_WARNING_PUSH \
202 Q_OBJECT_NO_ATTRIBUTES_WARNING \
203 Q_DECL_HIDDEN_STATIC_METACALL static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); \
204 QT_WARNING_POP \
205 QT_ANNOTATE_CLASS(qt_qgadget, "") \
206 /*end*/
207
208#define Q_NAMESPACE \
209 extern const QMetaObject staticMetaObject; \
210 QT_ANNOTATE_CLASS(qt_qnamespace, "") \
211 /*end*/
212
213#endif // QT_NO_META_MACROS
214
215#else // Q_MOC_RUN
216#define slots slots
217#define signals signals
218#define Q_SLOTS Q_SLOTS
219#define Q_SIGNALS Q_SIGNALS
220#define Q_CLASSINFO(name, value) Q_CLASSINFO(name, value)
221#define Q_INTERFACES(x) Q_INTERFACES(x)
222#define Q_PROPERTY(text) Q_PROPERTY(text)
223#define Q_PRIVATE_PROPERTY(d, text) Q_PRIVATE_PROPERTY(d, text)
224#define Q_REVISION(v) Q_REVISION(v)
225#define Q_OVERRIDE(text) Q_OVERRIDE(text)
226#define Q_ENUMS(x) Q_ENUMS(x)
227#define Q_FLAGS(x) Q_FLAGS(x)
228#define Q_ENUM(x) Q_ENUM(x)
229#define Q_FLAGS(x) Q_FLAGS(x)
230 /* qmake ignore Q_OBJECT */
231#define Q_OBJECT Q_OBJECT
232 /* qmake ignore Q_OBJECT */
233#define Q_OBJECT_FAKE Q_OBJECT_FAKE
234 /* qmake ignore Q_GADGET */
235#define Q_GADGET Q_GADGET
236#define Q_SCRIPTABLE Q_SCRIPTABLE
237#define Q_INVOKABLE Q_INVOKABLE
238#define Q_SIGNAL Q_SIGNAL
239#define Q_SLOT Q_SLOT
240#endif //Q_MOC_RUN
241
242#ifdef Q_CLANG_QDOC
243#undef Q_GADGET
244#define Q_GADGET
245#endif
246
247#ifndef QT_NO_META_MACROS
248// macro for onaming members
249#ifdef METHOD
250#undef METHOD
251#endif
252#ifdef SLOT
253#undef SLOT
254#endif
255#ifdef SIGNAL
256#undef SIGNAL
257#endif
258#endif // QT_NO_META_MACROS
259
260Q_CORE_EXPORT const char *qFlagLocation(const char *method);
261
262#ifndef QT_NO_META_MACROS
263#ifndef QT_NO_DEBUG
264# define QLOCATION "\0" __FILE__ ":" QT_STRINGIFY(__LINE__)
265# ifndef QT_NO_KEYWORDS
266# define METHOD(a) qFlagLocation("0"#a QLOCATION)
267# endif
268# define SLOT(a) qFlagLocation("1"#a QLOCATION)
269# define SIGNAL(a) qFlagLocation("2"#a QLOCATION)
270#else
271# ifndef QT_NO_KEYWORDS
272# define METHOD(a) "0"#a
273# endif
274# define SLOT(a) "1"#a
275# define SIGNAL(a) "2"#a
276#endif
277
278#define QMETHOD_CODE 0 // member type codes
279#define QSLOT_CODE 1
280#define QSIGNAL_CODE 2
281#endif // QT_NO_META_MACROS
282
283#define Q_ARG(type, data) QArgument<type >(#type, data)
284#define Q_RETURN_ARG(type, data) QReturnArgument<type >(#type, data)
285
286class QObject;
287class QMetaMethod;
288class QMetaEnum;
289class QMetaProperty;
290class QMetaClassInfo;
291
292
293class Q_CORE_EXPORT QGenericArgument
294{
295public:
296 inline QGenericArgument(const char *aName = Q_NULLPTR, const void *aData = Q_NULLPTR)
297 : _data(aData), _name(aName) {}
298 inline void *data() const { return const_cast<void *>(_data); }
299 inline const char *name() const { return _name; }
300
301private:
302 const void *_data;
303 const char *_name;
304};
305
306class Q_CORE_EXPORT QGenericReturnArgument: public QGenericArgument
307{
308public:
309 inline QGenericReturnArgument(const char *aName = Q_NULLPTR, void *aData = Q_NULLPTR)
310 : QGenericArgument(aName, aData)
311 {}
312};
313
314template <class T>
315class QArgument: public QGenericArgument
316{
317public:
318 inline QArgument(const char *aName, const T &aData)
319 : QGenericArgument(aName, static_cast<const void *>(&aData))
320 {}
321};
322template <class T>
323class QArgument<T &>: public QGenericArgument
324{
325public:
326 inline QArgument(const char *aName, T &aData)
327 : QGenericArgument(aName, static_cast<const void *>(&aData))
328 {}
329};
330
331
332template <typename T>
333class QReturnArgument: public QGenericReturnArgument
334{
335public:
336 inline QReturnArgument(const char *aName, T &aData)
337 : QGenericReturnArgument(aName, static_cast<void *>(&aData))
338 {}
339};
340
341struct Q_CORE_EXPORT QMetaObject
342{
343 class Connection;
344 const char *className() const;
345 const QMetaObject *superClass() const;
346
347 bool inherits(const QMetaObject *metaObject) const Q_DECL_NOEXCEPT;
348 QObject *cast(QObject *obj) const;
349 const QObject *cast(const QObject *obj) const;
350
351#ifndef QT_NO_TRANSLATION
352 QString tr(const char *s, const char *c, int n = -1) const;
353#endif // QT_NO_TRANSLATION
354
355 int methodOffset() const;
356 int enumeratorOffset() const;
357 int propertyOffset() const;
358 int classInfoOffset() const;
359
360 int constructorCount() const;
361 int methodCount() const;
362 int enumeratorCount() const;
363 int propertyCount() const;
364 int classInfoCount() const;
365
366 int indexOfConstructor(const char *constructor) const;
367 int indexOfMethod(const char *method) const;
368 int indexOfSignal(const char *signal) const;
369 int indexOfSlot(const char *slot) const;
370 int indexOfEnumerator(const char *name) const;
371 int indexOfProperty(const char *name) const;
372 int indexOfClassInfo(const char *name) const;
373
374 QMetaMethod constructor(int index) const;
375 QMetaMethod method(int index) const;
376 QMetaEnum enumerator(int index) const;
377 QMetaProperty property(int index) const;
378 QMetaClassInfo classInfo(int index) const;
379 QMetaProperty userProperty() const;
380
381 static bool checkConnectArgs(const char *signal, const char *method);
382 static bool checkConnectArgs(const QMetaMethod &signal,
383 const QMetaMethod &method);
384 static QByteArray normalizedSignature(const char *method);
385 static QByteArray normalizedType(const char *type);
386
387 // internal index-based connect
388 static Connection connect(const QObject *sender, int signal_index,
389 const QObject *receiver, int method_index,
390 int type = 0, int *types = Q_NULLPTR);
391 // internal index-based disconnect
392 static bool disconnect(const QObject *sender, int signal_index,
393 const QObject *receiver, int method_index);
394 static bool disconnectOne(const QObject *sender, int signal_index,
395 const QObject *receiver, int method_index);
396 // internal slot-name based connect
397 static void connectSlotsByName(QObject *o);
398
399 // internal index-based signal activation
400 static void activate(QObject *sender, int signal_index, void **argv);
401 static void activate(QObject *sender, const QMetaObject *, int local_signal_index, void **argv);
402 static void activate(QObject *sender, int signal_offset, int local_signal_index, void **argv);
403
404 static bool invokeMethod(QObject *obj, const char *member,
405 Qt::ConnectionType,
406 QGenericReturnArgument ret,
407 QGenericArgument val0 = QGenericArgument(Q_NULLPTR),
408 QGenericArgument val1 = QGenericArgument(),
409 QGenericArgument val2 = QGenericArgument(),
410 QGenericArgument val3 = QGenericArgument(),
411 QGenericArgument val4 = QGenericArgument(),
412 QGenericArgument val5 = QGenericArgument(),
413 QGenericArgument val6 = QGenericArgument(),
414 QGenericArgument val7 = QGenericArgument(),
415 QGenericArgument val8 = QGenericArgument(),
416 QGenericArgument val9 = QGenericArgument());
417
418 static inline bool invokeMethod(QObject *obj, const char *member,
419 QGenericReturnArgument ret,
420 QGenericArgument val0 = QGenericArgument(Q_NULLPTR),
421 QGenericArgument val1 = QGenericArgument(),
422 QGenericArgument val2 = QGenericArgument(),
423 QGenericArgument val3 = QGenericArgument(),
424 QGenericArgument val4 = QGenericArgument(),
425 QGenericArgument val5 = QGenericArgument(),
426 QGenericArgument val6 = QGenericArgument(),
427 QGenericArgument val7 = QGenericArgument(),
428 QGenericArgument val8 = QGenericArgument(),
429 QGenericArgument val9 = QGenericArgument())
430 {
431 return invokeMethod(obj, member, Qt::AutoConnection, ret, val0, val1, val2, val3,
432 val4, val5, val6, val7, val8, val9);
433 }
434
435 static inline bool invokeMethod(QObject *obj, const char *member,
436 Qt::ConnectionType type,
437 QGenericArgument val0 = QGenericArgument(Q_NULLPTR),
438 QGenericArgument val1 = QGenericArgument(),
439 QGenericArgument val2 = QGenericArgument(),
440 QGenericArgument val3 = QGenericArgument(),
441 QGenericArgument val4 = QGenericArgument(),
442 QGenericArgument val5 = QGenericArgument(),
443 QGenericArgument val6 = QGenericArgument(),
444 QGenericArgument val7 = QGenericArgument(),
445 QGenericArgument val8 = QGenericArgument(),
446 QGenericArgument val9 = QGenericArgument())
447 {
448 return invokeMethod(obj, member, type, QGenericReturnArgument(), val0, val1, val2,
449 val3, val4, val5, val6, val7, val8, val9);
450 }
451
452 static inline bool invokeMethod(QObject *obj, const char *member,
453 QGenericArgument val0 = QGenericArgument(Q_NULLPTR),
454 QGenericArgument val1 = QGenericArgument(),
455 QGenericArgument val2 = QGenericArgument(),
456 QGenericArgument val3 = QGenericArgument(),
457 QGenericArgument val4 = QGenericArgument(),
458 QGenericArgument val5 = QGenericArgument(),
459 QGenericArgument val6 = QGenericArgument(),
460 QGenericArgument val7 = QGenericArgument(),
461 QGenericArgument val8 = QGenericArgument(),
462 QGenericArgument val9 = QGenericArgument())
463 {
464 return invokeMethod(obj, member, Qt::AutoConnection, QGenericReturnArgument(), val0,
465 val1, val2, val3, val4, val5, val6, val7, val8, val9);
466 }
467
468#ifdef Q_QDOC
469 template<typename PointerToMemberFunction, typename MemberFunctionReturnType>
470 static bool invokeMethod(QObject *receiver, PointerToMemberFunction function, Qt::ConnectionType type = Qt::AutoConnection, MemberFunctionReturnType *ret = nullptr);
471 template<typename PointerToMemberFunction, typename MemberFunctionReturnType>
472 static bool invokeMethod(QObject *receiver, PointerToMemberFunction function, MemberFunctionReturnType *ret);
473 template<typename Functor, typename FunctorReturnType>
474 static bool invokeMethod(QObject *context, Functor function, Qt::ConnectionType type = Qt::AutoConnection, FunctorReturnType *ret = nullptr);
475 template<typename Functor, typename FunctorReturnType>
476 static bool invokeMethod(QObject *context, Functor function, FunctorReturnType *ret);
477#else
478
479 // invokeMethod() for member function pointer
480 template <typename Func>
481 static typename std::enable_if<QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
482 && !std::is_convertible<Func, const char*>::value
483 && QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
484 invokeMethod(typename QtPrivate::FunctionPointer<Func>::Object *object,
485 Func function,
486 Qt::ConnectionType type = Qt::AutoConnection,
487 typename QtPrivate::FunctionPointer<Func>::ReturnType *ret = nullptr)
488 {
489 return invokeMethodImpl(object, new QtPrivate::QSlotObjectWithNoArgs<Func>(function), type, ret);
490 }
491
492 template <typename Func>
493 static typename std::enable_if<QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
494 && !std::is_convertible<Func, const char*>::value
495 && QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
496 invokeMethod(typename QtPrivate::FunctionPointer<Func>::Object *object,
497 Func function,
498 typename QtPrivate::FunctionPointer<Func>::ReturnType *ret)
499 {
500 return invokeMethodImpl(object, new QtPrivate::QSlotObjectWithNoArgs<Func>(function), Qt::AutoConnection, ret);
501 }
502
503 // invokeMethod() for function pointer (not member)
504 template <typename Func>
505 static typename std::enable_if<!QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
506 && !std::is_convertible<Func, const char*>::value
507 && QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
508 invokeMethod(QObject *context, Func function,
509 Qt::ConnectionType type = Qt::AutoConnection,
510 typename QtPrivate::FunctionPointer<Func>::ReturnType *ret = nullptr)
511 {
512 return invokeMethodImpl(context, new QtPrivate::QFunctorSlotObjectWithNoArgsImplicitReturn<Func>(function), type, ret);
513 }
514
515 template <typename Func>
516 static typename std::enable_if<!QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
517 && !std::is_convertible<Func, const char*>::value
518 && QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
519 invokeMethod(QObject *context, Func function,
520 typename QtPrivate::FunctionPointer<Func>::ReturnType *ret)
521 {
522 return invokeMethodImpl(context, new QtPrivate::QFunctorSlotObjectWithNoArgsImplicitReturn<Func>(function), Qt::AutoConnection, ret);
523 }
524
525 // invokeMethod() for Functor
526 template <typename Func>
527 static typename std::enable_if<!QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
528 && QtPrivate::FunctionPointer<Func>::ArgumentCount == -1
529 && !std::is_convertible<Func, const char*>::value, bool>::type
530 invokeMethod(QObject *context, Func function,
531 Qt::ConnectionType type = Qt::AutoConnection, decltype(function()) *ret = nullptr)
532 {
533 return invokeMethodImpl(context,
534 new QtPrivate::QFunctorSlotObjectWithNoArgs<Func, decltype(function())>(function),
535 type,
536 ret);
537 }
538
539 template <typename Func>
540 static typename std::enable_if<!QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
541 && QtPrivate::FunctionPointer<Func>::ArgumentCount == -1
542 && !std::is_convertible<Func, const char*>::value, bool>::type
543 invokeMethod(QObject *context, Func function, typename std::result_of<Func()>::type *ret)
544 {
545 return invokeMethodImpl(context,
546 new QtPrivate::QFunctorSlotObjectWithNoArgs<Func, decltype(function())>(function),
547 Qt::AutoConnection,
548 ret);
549 }
550
551#endif
552
553 QObject *newInstance(QGenericArgument val0 = QGenericArgument(Q_NULLPTR),
554 QGenericArgument val1 = QGenericArgument(),
555 QGenericArgument val2 = QGenericArgument(),
556 QGenericArgument val3 = QGenericArgument(),
557 QGenericArgument val4 = QGenericArgument(),
558 QGenericArgument val5 = QGenericArgument(),
559 QGenericArgument val6 = QGenericArgument(),
560 QGenericArgument val7 = QGenericArgument(),
561 QGenericArgument val8 = QGenericArgument(),
562 QGenericArgument val9 = QGenericArgument()) const;
563
564 enum Call {
565 InvokeMetaMethod,
566 ReadProperty,
567 WriteProperty,
568 ResetProperty,
569 QueryPropertyDesignable,
570 QueryPropertyScriptable,
571 QueryPropertyStored,
572 QueryPropertyEditable,
573 QueryPropertyUser,
574 CreateInstance,
575 IndexOfMethod,
576 RegisterPropertyMetaType,
577 RegisterMethodArgumentMetaType
578 };
579
580 int static_metacall(Call, int, void **) const;
581 static int metacall(QObject *, Call, int, void **);
582
583 struct { // private data
584 const QMetaObject *superdata;
585 const QByteArrayData *stringdata;
586 const uint *data;
587 typedef void (*StaticMetacallFunction)(QObject *, QMetaObject::Call, int, void **);
588 StaticMetacallFunction static_metacall;
589 const QMetaObject * const *relatedMetaObjects;
590 void *extradata; //reserved for future use
591 } d;
592
593private:
594 static bool invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *slot, Qt::ConnectionType type, void *ret);
595};
596
597class Q_CORE_EXPORT QMetaObject::Connection {
598 void *d_ptr; //QObjectPrivate::Connection*
599 explicit Connection(void *data) : d_ptr(data) { }
600 friend class QObject;
601 friend class QObjectPrivate;
602 friend struct QMetaObject;
603 bool isConnected_helper() const;
604public:
605 ~Connection();
606 Connection();
607 Connection(const Connection &other);
608 Connection &operator=(const Connection &other);
609#ifdef Q_QDOC
610 operator bool() const;
611#else
612 typedef void *Connection::*RestrictedBool;
613 operator RestrictedBool() const { return d_ptr && isConnected_helper() ? &Connection::d_ptr : Q_NULLPTR; }
614#endif
615
616#ifdef Q_COMPILER_RVALUE_REFS
617 inline Connection(Connection &&o) : d_ptr(o.d_ptr) { o.d_ptr = Q_NULLPTR; }
618 inline Connection &operator=(Connection &&other)
619 { qSwap(d_ptr, other.d_ptr); return *this; }
620#endif
621};
622
623inline const QMetaObject *QMetaObject::superClass() const
624{ return d.superdata; }
625
626namespace QtPrivate {
627 /* Trait that tells is a the Object has a Q_OBJECT macro */
628 template <typename Object> struct HasQ_OBJECT_Macro {
629 template <typename T>
630 static char test(int (T::*)(QMetaObject::Call, int, void **));
631 static int test(int (Object::*)(QMetaObject::Call, int, void **));
632 enum { Value = sizeof(test(&Object::qt_metacall)) == sizeof(int) };
633 };
634}
635
636QT_END_NAMESPACE
637
638#endif // QOBJECTDEFS_H
639