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 = nullptr, int n = -1) \
141 { return staticMetaObject.tr(s, c, n); } \
142 QT_DEPRECATED static inline QString trUtf8(const char *s, const char *c = 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/* qmake ignore Q_NAMESPACE */
209#define Q_NAMESPACE \
210 extern const QMetaObject staticMetaObject; \
211 QT_ANNOTATE_CLASS(qt_qnamespace, "") \
212 /*end*/
213
214#endif // QT_NO_META_MACROS
215
216#else // Q_MOC_RUN
217#define slots slots
218#define signals signals
219#define Q_SLOTS Q_SLOTS
220#define Q_SIGNALS Q_SIGNALS
221#define Q_CLASSINFO(name, value) Q_CLASSINFO(name, value)
222#define Q_INTERFACES(x) Q_INTERFACES(x)
223#define Q_PROPERTY(text) Q_PROPERTY(text)
224#define Q_PRIVATE_PROPERTY(d, text) Q_PRIVATE_PROPERTY(d, text)
225#define Q_REVISION(v) Q_REVISION(v)
226#define Q_OVERRIDE(text) Q_OVERRIDE(text)
227#define Q_ENUMS(x) Q_ENUMS(x)
228#define Q_FLAGS(x) Q_FLAGS(x)
229#define Q_ENUM(x) Q_ENUM(x)
230#define Q_FLAGS(x) Q_FLAGS(x)
231 /* qmake ignore Q_OBJECT */
232#define Q_OBJECT Q_OBJECT
233 /* qmake ignore Q_OBJECT */
234#define Q_OBJECT_FAKE Q_OBJECT_FAKE
235 /* qmake ignore Q_GADGET */
236#define Q_GADGET Q_GADGET
237#define Q_SCRIPTABLE Q_SCRIPTABLE
238#define Q_INVOKABLE Q_INVOKABLE
239#define Q_SIGNAL Q_SIGNAL
240#define Q_SLOT Q_SLOT
241#endif //Q_MOC_RUN
242
243#ifndef QT_NO_META_MACROS
244// macro for onaming members
245#ifdef METHOD
246#undef METHOD
247#endif
248#ifdef SLOT
249#undef SLOT
250#endif
251#ifdef SIGNAL
252#undef SIGNAL
253#endif
254#endif // QT_NO_META_MACROS
255
256Q_CORE_EXPORT const char *qFlagLocation(const char *method);
257
258#ifndef QT_NO_META_MACROS
259#ifndef QT_NO_DEBUG
260# define QLOCATION "\0" __FILE__ ":" QT_STRINGIFY(__LINE__)
261# ifndef QT_NO_KEYWORDS
262# define METHOD(a) qFlagLocation("0"#a QLOCATION)
263# endif
264# define SLOT(a) qFlagLocation("1"#a QLOCATION)
265# define SIGNAL(a) qFlagLocation("2"#a QLOCATION)
266#else
267# ifndef QT_NO_KEYWORDS
268# define METHOD(a) "0"#a
269# endif
270# define SLOT(a) "1"#a
271# define SIGNAL(a) "2"#a
272#endif
273
274#define QMETHOD_CODE 0 // member type codes
275#define QSLOT_CODE 1
276#define QSIGNAL_CODE 2
277#endif // QT_NO_META_MACROS
278
279#define Q_ARG(type, data) QArgument<type >(#type, data)
280#define Q_RETURN_ARG(type, data) QReturnArgument<type >(#type, data)
281
282class QObject;
283class QMetaMethod;
284class QMetaEnum;
285class QMetaProperty;
286class QMetaClassInfo;
287
288
289class Q_CORE_EXPORT QGenericArgument
290{
291public:
292 inline QGenericArgument(const char *aName = nullptr, const void *aData = nullptr)
293 : _data(aData), _name(aName) {}
294 inline void *data() const { return const_cast<void *>(_data); }
295 inline const char *name() const { return _name; }
296
297private:
298 const void *_data;
299 const char *_name;
300};
301
302class Q_CORE_EXPORT QGenericReturnArgument: public QGenericArgument
303{
304public:
305 inline QGenericReturnArgument(const char *aName = nullptr, void *aData = nullptr)
306 : QGenericArgument(aName, aData)
307 {}
308};
309
310template <class T>
311class QArgument: public QGenericArgument
312{
313public:
314 inline QArgument(const char *aName, const T &aData)
315 : QGenericArgument(aName, static_cast<const void *>(&aData))
316 {}
317};
318template <class T>
319class QArgument<T &>: public QGenericArgument
320{
321public:
322 inline QArgument(const char *aName, T &aData)
323 : QGenericArgument(aName, static_cast<const void *>(&aData))
324 {}
325};
326
327
328template <typename T>
329class QReturnArgument: public QGenericReturnArgument
330{
331public:
332 inline QReturnArgument(const char *aName, T &aData)
333 : QGenericReturnArgument(aName, static_cast<void *>(&aData))
334 {}
335};
336
337struct Q_CORE_EXPORT QMetaObject
338{
339 class Connection;
340 const char *className() const;
341 const QMetaObject *superClass() const;
342
343 bool inherits(const QMetaObject *metaObject) const Q_DECL_NOEXCEPT;
344 QObject *cast(QObject *obj) const;
345 const QObject *cast(const QObject *obj) const;
346
347#if !defined(QT_NO_TRANSLATION) || defined(Q_CLANG_QDOC)
348 QString tr(const char *s, const char *c, int n = -1) const;
349#endif // QT_NO_TRANSLATION
350
351 int methodOffset() const;
352 int enumeratorOffset() const;
353 int propertyOffset() const;
354 int classInfoOffset() const;
355
356 int constructorCount() const;
357 int methodCount() const;
358 int enumeratorCount() const;
359 int propertyCount() const;
360 int classInfoCount() const;
361
362 int indexOfConstructor(const char *constructor) const;
363 int indexOfMethod(const char *method) const;
364 int indexOfSignal(const char *signal) const;
365 int indexOfSlot(const char *slot) const;
366 int indexOfEnumerator(const char *name) const;
367 int indexOfProperty(const char *name) const;
368 int indexOfClassInfo(const char *name) const;
369
370 QMetaMethod constructor(int index) const;
371 QMetaMethod method(int index) const;
372 QMetaEnum enumerator(int index) const;
373 QMetaProperty property(int index) const;
374 QMetaClassInfo classInfo(int index) const;
375 QMetaProperty userProperty() const;
376
377 static bool checkConnectArgs(const char *signal, const char *method);
378 static bool checkConnectArgs(const QMetaMethod &signal,
379 const QMetaMethod &method);
380 static QByteArray normalizedSignature(const char *method);
381 static QByteArray normalizedType(const char *type);
382
383 // internal index-based connect
384 static Connection connect(const QObject *sender, int signal_index,
385 const QObject *receiver, int method_index,
386 int type = 0, int *types = nullptr);
387 // internal index-based disconnect
388 static bool disconnect(const QObject *sender, int signal_index,
389 const QObject *receiver, int method_index);
390 static bool disconnectOne(const QObject *sender, int signal_index,
391 const QObject *receiver, int method_index);
392 // internal slot-name based connect
393 static void connectSlotsByName(QObject *o);
394
395 // internal index-based signal activation
396 static void activate(QObject *sender, int signal_index, void **argv);
397 static void activate(QObject *sender, const QMetaObject *, int local_signal_index, void **argv);
398 static void activate(QObject *sender, int signal_offset, int local_signal_index, void **argv);
399
400 static bool invokeMethod(QObject *obj, const char *member,
401 Qt::ConnectionType,
402 QGenericReturnArgument ret,
403 QGenericArgument val0 = QGenericArgument(nullptr),
404 QGenericArgument val1 = QGenericArgument(),
405 QGenericArgument val2 = QGenericArgument(),
406 QGenericArgument val3 = QGenericArgument(),
407 QGenericArgument val4 = QGenericArgument(),
408 QGenericArgument val5 = QGenericArgument(),
409 QGenericArgument val6 = QGenericArgument(),
410 QGenericArgument val7 = QGenericArgument(),
411 QGenericArgument val8 = QGenericArgument(),
412 QGenericArgument val9 = QGenericArgument());
413
414 static inline bool invokeMethod(QObject *obj, const char *member,
415 QGenericReturnArgument ret,
416 QGenericArgument val0 = QGenericArgument(nullptr),
417 QGenericArgument val1 = QGenericArgument(),
418 QGenericArgument val2 = QGenericArgument(),
419 QGenericArgument val3 = QGenericArgument(),
420 QGenericArgument val4 = QGenericArgument(),
421 QGenericArgument val5 = QGenericArgument(),
422 QGenericArgument val6 = QGenericArgument(),
423 QGenericArgument val7 = QGenericArgument(),
424 QGenericArgument val8 = QGenericArgument(),
425 QGenericArgument val9 = QGenericArgument())
426 {
427 return invokeMethod(obj, member, Qt::AutoConnection, ret, val0, val1, val2, val3,
428 val4, val5, val6, val7, val8, val9);
429 }
430
431 static inline bool invokeMethod(QObject *obj, const char *member,
432 Qt::ConnectionType type,
433 QGenericArgument val0 = QGenericArgument(nullptr),
434 QGenericArgument val1 = QGenericArgument(),
435 QGenericArgument val2 = QGenericArgument(),
436 QGenericArgument val3 = QGenericArgument(),
437 QGenericArgument val4 = QGenericArgument(),
438 QGenericArgument val5 = QGenericArgument(),
439 QGenericArgument val6 = QGenericArgument(),
440 QGenericArgument val7 = QGenericArgument(),
441 QGenericArgument val8 = QGenericArgument(),
442 QGenericArgument val9 = QGenericArgument())
443 {
444 return invokeMethod(obj, member, type, QGenericReturnArgument(), val0, val1, val2,
445 val3, val4, val5, val6, val7, val8, val9);
446 }
447
448 static inline bool invokeMethod(QObject *obj, const char *member,
449 QGenericArgument val0 = QGenericArgument(nullptr),
450 QGenericArgument val1 = QGenericArgument(),
451 QGenericArgument val2 = QGenericArgument(),
452 QGenericArgument val3 = QGenericArgument(),
453 QGenericArgument val4 = QGenericArgument(),
454 QGenericArgument val5 = QGenericArgument(),
455 QGenericArgument val6 = QGenericArgument(),
456 QGenericArgument val7 = QGenericArgument(),
457 QGenericArgument val8 = QGenericArgument(),
458 QGenericArgument val9 = QGenericArgument())
459 {
460 return invokeMethod(obj, member, Qt::AutoConnection, QGenericReturnArgument(), val0,
461 val1, val2, val3, val4, val5, val6, val7, val8, val9);
462 }
463
464#ifdef Q_CLANG_QDOC
465 template<typename Functor, typename FunctorReturnType>
466 static bool invokeMethod(QObject *context, Functor function, Qt::ConnectionType type = Qt::AutoConnection, FunctorReturnType *ret = nullptr);
467 template<typename Functor, typename FunctorReturnType>
468 static bool invokeMethod(QObject *context, Functor function, FunctorReturnType *ret);
469#else
470
471 // invokeMethod() for member function pointer
472 template <typename Func>
473 static typename std::enable_if<QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
474 && !std::is_convertible<Func, const char*>::value
475 && QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
476 invokeMethod(typename QtPrivate::FunctionPointer<Func>::Object *object,
477 Func function,
478 Qt::ConnectionType type = Qt::AutoConnection,
479 typename QtPrivate::FunctionPointer<Func>::ReturnType *ret = nullptr)
480 {
481 return invokeMethodImpl(object, new QtPrivate::QSlotObjectWithNoArgs<Func>(function), type, ret);
482 }
483
484 template <typename Func>
485 static typename std::enable_if<QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
486 && !std::is_convertible<Func, const char*>::value
487 && QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
488 invokeMethod(typename QtPrivate::FunctionPointer<Func>::Object *object,
489 Func function,
490 typename QtPrivate::FunctionPointer<Func>::ReturnType *ret)
491 {
492 return invokeMethodImpl(object, new QtPrivate::QSlotObjectWithNoArgs<Func>(function), Qt::AutoConnection, ret);
493 }
494
495 // invokeMethod() for function pointer (not member)
496 template <typename Func>
497 static typename std::enable_if<!QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
498 && !std::is_convertible<Func, const char*>::value
499 && QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
500 invokeMethod(QObject *context, Func function,
501 Qt::ConnectionType type = Qt::AutoConnection,
502 typename QtPrivate::FunctionPointer<Func>::ReturnType *ret = nullptr)
503 {
504 return invokeMethodImpl(context, new QtPrivate::QFunctorSlotObjectWithNoArgsImplicitReturn<Func>(function), type, ret);
505 }
506
507 template <typename Func>
508 static typename std::enable_if<!QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
509 && !std::is_convertible<Func, const char*>::value
510 && QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::type
511 invokeMethod(QObject *context, Func function,
512 typename QtPrivate::FunctionPointer<Func>::ReturnType *ret)
513 {
514 return invokeMethodImpl(context, new QtPrivate::QFunctorSlotObjectWithNoArgsImplicitReturn<Func>(function), Qt::AutoConnection, ret);
515 }
516
517 // invokeMethod() for Functor
518 template <typename Func>
519 static typename std::enable_if<!QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
520 && QtPrivate::FunctionPointer<Func>::ArgumentCount == -1
521 && !std::is_convertible<Func, const char*>::value, bool>::type
522 invokeMethod(QObject *context, Func function,
523 Qt::ConnectionType type = Qt::AutoConnection, decltype(function()) *ret = nullptr)
524 {
525 return invokeMethodImpl(context,
526 new QtPrivate::QFunctorSlotObjectWithNoArgs<Func, decltype(function())>(function),
527 type,
528 ret);
529 }
530
531 template <typename Func>
532 static typename std::enable_if<!QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction
533 && QtPrivate::FunctionPointer<Func>::ArgumentCount == -1
534 && !std::is_convertible<Func, const char*>::value, bool>::type
535 invokeMethod(QObject *context, Func function, typename std::result_of<Func()>::type *ret)
536 {
537 return invokeMethodImpl(context,
538 new QtPrivate::QFunctorSlotObjectWithNoArgs<Func, decltype(function())>(function),
539 Qt::AutoConnection,
540 ret);
541 }
542
543#endif
544
545 QObject *newInstance(QGenericArgument val0 = QGenericArgument(nullptr),
546 QGenericArgument val1 = QGenericArgument(),
547 QGenericArgument val2 = QGenericArgument(),
548 QGenericArgument val3 = QGenericArgument(),
549 QGenericArgument val4 = QGenericArgument(),
550 QGenericArgument val5 = QGenericArgument(),
551 QGenericArgument val6 = QGenericArgument(),
552 QGenericArgument val7 = QGenericArgument(),
553 QGenericArgument val8 = QGenericArgument(),
554 QGenericArgument val9 = QGenericArgument()) const;
555
556 enum Call {
557 InvokeMetaMethod,
558 ReadProperty,
559 WriteProperty,
560 ResetProperty,
561 QueryPropertyDesignable,
562 QueryPropertyScriptable,
563 QueryPropertyStored,
564 QueryPropertyEditable,
565 QueryPropertyUser,
566 CreateInstance,
567 IndexOfMethod,
568 RegisterPropertyMetaType,
569 RegisterMethodArgumentMetaType
570 };
571
572 int static_metacall(Call, int, void **) const;
573 static int metacall(QObject *, Call, int, void **);
574
575 struct { // private data
576 const QMetaObject *superdata;
577 const QByteArrayData *stringdata;
578 const uint *data;
579 typedef void (*StaticMetacallFunction)(QObject *, QMetaObject::Call, int, void **);
580 StaticMetacallFunction static_metacall;
581 const QMetaObject * const *relatedMetaObjects;
582 void *extradata; //reserved for future use
583 } d;
584
585private:
586 static bool invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *slot, Qt::ConnectionType type, void *ret);
587};
588
589class Q_CORE_EXPORT QMetaObject::Connection {
590 void *d_ptr; //QObjectPrivate::Connection*
591 explicit Connection(void *data) : d_ptr(data) { }
592 friend class QObject;
593 friend class QObjectPrivate;
594 friend struct QMetaObject;
595 bool isConnected_helper() const;
596public:
597 ~Connection();
598 Connection();
599 Connection(const Connection &other);
600 Connection &operator=(const Connection &other);
601#ifdef Q_QDOC
602 operator bool() const;
603#else
604 typedef void *Connection::*RestrictedBool;
605 operator RestrictedBool() const { return d_ptr && isConnected_helper() ? &Connection::d_ptr : nullptr; }
606#endif
607
608 Connection(Connection &&o) Q_DECL_NOTHROW : d_ptr(o.d_ptr) { o.d_ptr = nullptr; }
609 Connection &operator=(Connection &&other) Q_DECL_NOTHROW
610 { qSwap(d_ptr, other.d_ptr); return *this; }
611};
612
613inline const QMetaObject *QMetaObject::superClass() const
614{ return d.superdata; }
615
616namespace QtPrivate {
617 /* Trait that tells is a the Object has a Q_OBJECT macro */
618 template <typename Object> struct HasQ_OBJECT_Macro {
619 template <typename T>
620 static char test(int (T::*)(QMetaObject::Call, int, void **));
621 static int test(int (Object::*)(QMetaObject::Call, int, void **));
622 enum { Value = sizeof(test(&Object::qt_metacall)) == sizeof(int) };
623 };
624}
625
626QT_END_NAMESPACE
627
628#endif // QOBJECTDEFS_H
629