File indexing completed on 2025-01-18 10:07:32
0001
0002
0003
0004
0005 #ifndef QOBJECTDEFS_H
0006 #define QOBJECTDEFS_H
0007
0008 #if defined(__OBJC__) && !defined(__cplusplus)
0009 # warning "File built in Objective-C mode (.m), but using Qt requires Objective-C++ (.mm)"
0010 #endif
0011
0012 #include <QtCore/qnamespace.h>
0013 #include <QtCore/qobjectdefs_impl.h>
0014 #include <QtCore/qtcoreexports.h>
0015 #include <QtCore/qtmetamacros.h>
0016
0017 QT_BEGIN_NAMESPACE
0018
0019 class QByteArray;
0020 struct QArrayData;
0021
0022 class QString;
0023
0024 #ifndef QT_NO_META_MACROS
0025
0026 #ifdef METHOD
0027 #undef METHOD
0028 #endif
0029 #ifdef SLOT
0030 #undef SLOT
0031 #endif
0032 #ifdef SIGNAL
0033 #undef SIGNAL
0034 #endif
0035 #endif
0036
0037 Q_CORE_EXPORT const char *qFlagLocation(const char *method);
0038
0039 #ifndef QT_NO_META_MACROS
0040 # define QMETHOD_CODE 0
0041 # define QSLOT_CODE 1
0042 # define QSIGNAL_CODE 2
0043 # define QT_PREFIX_CODE(code, a) QT_STRINGIFY(code) #a
0044 # define QT_STRINGIFY_METHOD(a) QT_PREFIX_CODE(QMETHOD_CODE, a)
0045 # define QT_STRINGIFY_SLOT(a) QT_PREFIX_CODE(QSLOT_CODE, a)
0046 # define QT_STRINGIFY_SIGNAL(a) QT_PREFIX_CODE(QSIGNAL_CODE, a)
0047 # ifndef QT_NO_DEBUG
0048 # define QLOCATION "\0" __FILE__ ":" QT_STRINGIFY(__LINE__)
0049 # ifndef QT_NO_KEYWORDS
0050 # define METHOD(a) qFlagLocation(QT_STRINGIFY_METHOD(a) QLOCATION)
0051 # endif
0052 # define SLOT(a) qFlagLocation(QT_STRINGIFY_SLOT(a) QLOCATION)
0053 # define SIGNAL(a) qFlagLocation(QT_STRINGIFY_SIGNAL(a) QLOCATION)
0054 # else
0055 # ifndef QT_NO_KEYWORDS
0056 # define METHOD(a) QT_STRINGIFY_METHOD(a)
0057 # endif
0058 # define SLOT(a) QT_STRINGIFY_SLOT(a)
0059 # define SIGNAL(a) QT_STRINGIFY_SIGNAL(a)
0060 # endif
0061 #endif
0062
0063 #define Q_ARG(Type, data) QtPrivate::Invoke::argument<Type>(QT_STRINGIFY(Type), data)
0064 #define Q_RETURN_ARG(Type, data) QtPrivate::Invoke::returnArgument<Type>(QT_STRINGIFY(Type), data)
0065
0066 class QObject;
0067 class QMetaMethod;
0068 class QMetaEnum;
0069 class QMetaProperty;
0070 class QMetaClassInfo;
0071
0072 namespace QtPrivate {
0073 class QMetaTypeInterface;
0074 template<typename T> constexpr const QMetaTypeInterface *qMetaTypeInterfaceForType();
0075 }
0076
0077 struct QMethodRawArguments
0078 {
0079 void **arguments;
0080 };
0081
0082 #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
0083 class Q_CORE_EXPORT QGenericArgument
0084 {
0085 public:
0086 inline QGenericArgument(const char *aName = nullptr, const void *aData = nullptr)
0087 : _data(aData), _name(aName) {}
0088 inline void *data() const { return const_cast<void *>(_data); }
0089 inline const char *name() const { return _name; }
0090
0091 private:
0092 const void *_data;
0093 const char *_name;
0094 };
0095
0096 class Q_CORE_EXPORT QGenericReturnArgument: public QGenericArgument
0097 {
0098 public:
0099 inline QGenericReturnArgument(const char *aName = nullptr, void *aData = nullptr)
0100 : QGenericArgument(aName, aData)
0101 {}
0102 };
0103
0104 template <class T>
0105 class QArgument: public QGenericArgument
0106 {
0107 public:
0108 inline QArgument(const char *aName, const T &aData)
0109 : QGenericArgument(aName, static_cast<const void *>(&aData))
0110 {}
0111 };
0112 template <class T>
0113 class QArgument<T &>: public QGenericArgument
0114 {
0115 public:
0116 inline QArgument(const char *aName, T &aData)
0117 : QGenericArgument(aName, static_cast<const void *>(&aData))
0118 {}
0119 };
0120
0121
0122 template <typename T>
0123 class QReturnArgument: public QGenericReturnArgument
0124 {
0125 public:
0126 inline QReturnArgument(const char *aName, T &aData)
0127 : QGenericReturnArgument(aName, static_cast<void *>(&aData))
0128 {}
0129 };
0130 #endif
0131
0132 struct QMetaMethodArgument
0133 {
0134 const QtPrivate::QMetaTypeInterface *metaType;
0135 const char *name;
0136 const void *data;
0137 };
0138
0139 struct QMetaMethodReturnArgument
0140 {
0141 const QtPrivate::QMetaTypeInterface *metaType;
0142 const char *name;
0143 void *data;
0144 };
0145
0146 template <typename T>
0147 struct QTemplatedMetaMethodReturnArgument : QMetaMethodReturnArgument
0148 {
0149 using Type = T;
0150 };
0151
0152 namespace QtPrivate {
0153 namespace Invoke {
0154 #if QT_VERSION <= QT_VERSION_CHECK(7, 0, 0)
0155 template <typename... Args>
0156 using AreOldStyleArgs = std::disjunction<std::is_base_of<QGenericArgument, Args>...>;
0157
0158 template <typename T, typename... Args> using IfNotOldStyleArgs =
0159 std::enable_if_t<!AreOldStyleArgs<Args...>::value, T>;
0160 #else
0161 template <typename T, typename... Args> using IfNotOldStyleArgs = T;
0162 #endif
0163
0164 template <typename T> inline QMetaMethodArgument argument(const char *name, const T &t)
0165 {
0166 if constexpr ((std::is_lvalue_reference_v<T> && std::is_const_v<std::remove_reference_t<T>>) ||
0167 !std::is_reference_v<T>) {
0168 return { qMetaTypeInterfaceForType<T>(), name, std::addressof(t) };
0169 } else {
0170 return { nullptr, name, std::addressof(t) };
0171 }
0172 }
0173
0174 template <typename T>
0175 inline QTemplatedMetaMethodReturnArgument<T> returnArgument(const char *name, T &t)
0176 {
0177 return { qMetaTypeInterfaceForType<T>(), name, std::addressof(t) };
0178 }
0179
0180 template <typename T> inline const char *typenameHelper(const T &)
0181 {
0182 return nullptr;
0183 }
0184 template <typename T> inline const void *dataHelper(const T &t)
0185 {
0186 return std::addressof(t);
0187 }
0188 template <typename T> inline const QMetaTypeInterface *metaTypeHelper(const T &)
0189 {
0190 return qMetaTypeInterfaceForType<T>();
0191 }
0192
0193 inline const char *typenameHelper(QMetaMethodArgument a)
0194 { return a.name; }
0195 inline const void *dataHelper(QMetaMethodArgument a)
0196 { return a.data; }
0197 inline const QMetaTypeInterface *metaTypeHelper(QMetaMethodArgument a)
0198 { return a.metaType; }
0199
0200 inline const char *typenameHelper(const char *) = delete;
0201 template <typename T> inline const void *dataHelper(const char *) = delete;
0202 inline const QMetaTypeInterface *metaTypeHelper(const char *) = delete;
0203 inline const char *typenameHelper(const char16_t *) = delete;
0204 template <typename T> inline const void *dataHelper(const char16_t *) = delete;
0205 inline const QMetaTypeInterface *metaTypeHelper(const char16_t *) = delete;
0206
0207 }
0208
0209 template <typename... Args> inline auto invokeMethodHelper(QMetaMethodReturnArgument r, const Args &... arguments)
0210 {
0211 std::array params = { const_cast<const void *>(r.data), Invoke::dataHelper(arguments)... };
0212 std::array names = { r.name, Invoke::typenameHelper(arguments)... };
0213 std::array types = { r.metaType, Invoke::metaTypeHelper(arguments)... };
0214 static_assert(params.size() == types.size());
0215 static_assert(params.size() == names.size());
0216
0217 struct R {
0218 decltype(params) parameters;
0219 decltype(names) typeNames;
0220 decltype(types) metaTypes;
0221 constexpr qsizetype parameterCount() const { return qsizetype(parameters.size()); }
0222 };
0223 return R { params, names, types };
0224 }
0225 }
0226
0227 template <typename T> void qReturnArg(const T &&) = delete;
0228 template <typename T> inline QTemplatedMetaMethodReturnArgument<T> qReturnArg(T &data)
0229 {
0230 return QtPrivate::Invoke::returnArgument(nullptr, data);
0231 }
0232
0233 struct Q_CORE_EXPORT QMetaObject
0234 {
0235 class Connection;
0236 const char *className() const;
0237 const QMetaObject *superClass() const;
0238
0239 bool inherits(const QMetaObject *metaObject) const noexcept;
0240 QObject *cast(QObject *obj) const
0241 { return const_cast<QObject *>(cast(const_cast<const QObject *>(obj))); }
0242 const QObject *cast(const QObject *obj) const;
0243
0244 #if !defined(QT_NO_TRANSLATION) || defined(Q_QDOC)
0245 QString tr(const char *s, const char *c, int n = -1) const;
0246 #endif
0247
0248 QMetaType metaType() const;
0249
0250 int methodOffset() const;
0251 int enumeratorOffset() const;
0252 int propertyOffset() const;
0253 int classInfoOffset() const;
0254
0255 int constructorCount() const;
0256 int methodCount() const;
0257 int enumeratorCount() const;
0258 int propertyCount() const;
0259 int classInfoCount() const;
0260
0261 int indexOfConstructor(const char *constructor) const;
0262 int indexOfMethod(const char *method) const;
0263 int indexOfSignal(const char *signal) const;
0264 int indexOfSlot(const char *slot) const;
0265 int indexOfEnumerator(const char *name) const;
0266
0267 int indexOfProperty(const char *name) const;
0268 int indexOfClassInfo(const char *name) const;
0269
0270 QMetaMethod constructor(int index) const;
0271 QMetaMethod method(int index) const;
0272 QMetaEnum enumerator(int index) const;
0273 QMetaProperty property(int index) const;
0274 QMetaClassInfo classInfo(int index) const;
0275 QMetaProperty userProperty() const;
0276
0277 static bool checkConnectArgs(const char *signal, const char *method);
0278 static bool checkConnectArgs(const QMetaMethod &signal,
0279 const QMetaMethod &method);
0280 static QByteArray normalizedSignature(const char *method);
0281 static QByteArray normalizedType(const char *type);
0282
0283
0284 static Connection connect(const QObject *sender, int signal_index,
0285 const QObject *receiver, int method_index,
0286 int type = 0, int *types = nullptr);
0287
0288 static bool disconnect(const QObject *sender, int signal_index,
0289 const QObject *receiver, int method_index);
0290 static bool disconnectOne(const QObject *sender, int signal_index,
0291 const QObject *receiver, int method_index);
0292
0293 static void connectSlotsByName(QObject *o);
0294
0295
0296 static void activate(QObject *sender, int signal_index, void **argv);
0297 static void activate(QObject *sender, const QMetaObject *, int local_signal_index, void **argv);
0298 static void activate(QObject *sender, int signal_offset, int local_signal_index, void **argv);
0299
0300 #if QT_VERSION <= QT_VERSION_CHECK(7, 0, 0)
0301 static bool invokeMethod(QObject *obj, const char *member,
0302 Qt::ConnectionType,
0303 QGenericReturnArgument ret,
0304 QGenericArgument val0 = QGenericArgument(nullptr),
0305 QGenericArgument val1 = QGenericArgument(),
0306 QGenericArgument val2 = QGenericArgument(),
0307 QGenericArgument val3 = QGenericArgument(),
0308 QGenericArgument val4 = QGenericArgument(),
0309 QGenericArgument val5 = QGenericArgument(),
0310 QGenericArgument val6 = QGenericArgument(),
0311 QGenericArgument val7 = QGenericArgument(),
0312 QGenericArgument val8 = QGenericArgument(),
0313 QGenericArgument val9 = QGenericArgument());
0314
0315 static inline bool invokeMethod(QObject *obj, const char *member,
0316 QGenericReturnArgument ret,
0317 QGenericArgument val0 = QGenericArgument(nullptr),
0318 QGenericArgument val1 = QGenericArgument(),
0319 QGenericArgument val2 = QGenericArgument(),
0320 QGenericArgument val3 = QGenericArgument(),
0321 QGenericArgument val4 = QGenericArgument(),
0322 QGenericArgument val5 = QGenericArgument(),
0323 QGenericArgument val6 = QGenericArgument(),
0324 QGenericArgument val7 = QGenericArgument(),
0325 QGenericArgument val8 = QGenericArgument(),
0326 QGenericArgument val9 = QGenericArgument())
0327 {
0328 return invokeMethod(obj, member, Qt::AutoConnection, ret, val0, val1, val2, val3,
0329 val4, val5, val6, val7, val8, val9);
0330 }
0331
0332 static inline bool invokeMethod(QObject *obj, const char *member,
0333 Qt::ConnectionType type,
0334 QGenericArgument val0,
0335 QGenericArgument val1 = QGenericArgument(),
0336 QGenericArgument val2 = QGenericArgument(),
0337 QGenericArgument val3 = QGenericArgument(),
0338 QGenericArgument val4 = QGenericArgument(),
0339 QGenericArgument val5 = QGenericArgument(),
0340 QGenericArgument val6 = QGenericArgument(),
0341 QGenericArgument val7 = QGenericArgument(),
0342 QGenericArgument val8 = QGenericArgument(),
0343 QGenericArgument val9 = QGenericArgument())
0344 {
0345 return invokeMethod(obj, member, type, QGenericReturnArgument(), val0, val1, val2,
0346 val3, val4, val5, val6, val7, val8, val9);
0347 }
0348
0349 static inline bool invokeMethod(QObject *obj, const char *member,
0350 QGenericArgument val0,
0351 QGenericArgument val1 = QGenericArgument(),
0352 QGenericArgument val2 = QGenericArgument(),
0353 QGenericArgument val3 = QGenericArgument(),
0354 QGenericArgument val4 = QGenericArgument(),
0355 QGenericArgument val5 = QGenericArgument(),
0356 QGenericArgument val6 = QGenericArgument(),
0357 QGenericArgument val7 = QGenericArgument(),
0358 QGenericArgument val8 = QGenericArgument(),
0359 QGenericArgument val9 = QGenericArgument())
0360 {
0361 return invokeMethod(obj, member, Qt::AutoConnection, QGenericReturnArgument(), val0,
0362 val1, val2, val3, val4, val5, val6, val7, val8, val9);
0363 }
0364 #endif
0365
0366 template <typename ReturnArg, typename... Args> static
0367 #ifdef Q_QDOC
0368 bool
0369 #else
0370 QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...>
0371 #endif
0372 invokeMethod(QObject *obj, const char *member, Qt::ConnectionType c,
0373 QTemplatedMetaMethodReturnArgument<ReturnArg> r, Args &&... arguments)
0374 {
0375 auto h = QtPrivate::invokeMethodHelper(r, std::forward<Args>(arguments)...);
0376 return invokeMethodImpl(obj, member, c, h.parameterCount(), h.parameters.data(),
0377 h.typeNames.data(), h.metaTypes.data());
0378 }
0379
0380 template <typename... Args> static
0381 #ifdef Q_QDOC
0382 bool
0383 #else
0384 QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...>
0385 #endif
0386 invokeMethod(QObject *obj, const char *member, Qt::ConnectionType c, Args &&... arguments)
0387 {
0388 QTemplatedMetaMethodReturnArgument<void> r = {};
0389 return invokeMethod(obj, member, c, r, std::forward<Args>(arguments)...);
0390 }
0391
0392 template <typename ReturnArg, typename... Args> static
0393 #ifdef Q_QDOC
0394 bool
0395 #else
0396 QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...>
0397 #endif
0398 invokeMethod(QObject *obj, const char *member, QTemplatedMetaMethodReturnArgument<ReturnArg> r,
0399 Args &&... arguments)
0400 {
0401 return invokeMethod(obj, member, Qt::AutoConnection, r, std::forward<Args>(arguments)...);
0402 }
0403
0404 template <typename... Args> static
0405 #ifdef Q_QDOC
0406 bool
0407 #else
0408 QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...>
0409 #endif
0410 invokeMethod(QObject *obj, const char *member, Args &&... arguments)
0411 {
0412 QTemplatedMetaMethodReturnArgument<void> r = {};
0413 return invokeMethod(obj, member, Qt::AutoConnection, r, std::forward<Args>(arguments)...);
0414 }
0415
0416 #ifdef Q_QDOC
0417 template<typename Functor, typename FunctorReturnType>
0418 static bool invokeMethod(QObject *context, Functor &&function, Qt::ConnectionType type = Qt::AutoConnection, FunctorReturnType *ret = nullptr);
0419 template<typename Functor, typename FunctorReturnType>
0420 static bool invokeMethod(QObject *context, Functor &&function, FunctorReturnType *ret);
0421
0422 template<typename Functor, typename FunctorReturnType, typename... Args>
0423 static bool invokeMethod(QObject *context, Functor &&function, Qt::ConnectionType type, QTemplatedMetaMethodReturnArgument<FunctorReturnType> ret, Args &&...arguments);
0424 template<typename Functor, typename FunctorReturnType, typename... Args>
0425 static bool invokeMethod(QObject *context, Functor &&function, QTemplatedMetaMethodReturnArgument<FunctorReturnType> ret, Args &&...arguments);
0426 template<typename Functor, typename... Args>
0427 static bool invokeMethod(QObject *context, Functor &&function, Qt::ConnectionType type, Args &&...arguments);
0428 template<typename Functor, typename... Args>
0429 static bool invokeMethod(QObject *context, Functor &&function, Args &&...arguments);
0430 #else
0431 template <typename Func>
0432 static std::enable_if_t<!std::disjunction_v<std::is_convertible<Func, const char *>,
0433 QtPrivate::Invoke::AreOldStyleArgs<Func>>,
0434 bool>
0435 invokeMethod(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
0436 Func &&function, Qt::ConnectionType type,
0437 typename QtPrivate::Callable<Func>::ReturnType *ret)
0438 {
0439 using R = typename QtPrivate::Callable<Func>::ReturnType;
0440 const auto getReturnArg = [ret]() -> QTemplatedMetaMethodReturnArgument<R> {
0441 if constexpr (std::is_void_v<R>)
0442 return {};
0443 else
0444 return ret ? qReturnArg(*ret) : QTemplatedMetaMethodReturnArgument<R>{};
0445 };
0446 return invokeMethod(object, std::forward<Func>(function), type, getReturnArg());
0447 }
0448 template <typename Func>
0449 static std::enable_if_t<!std::disjunction_v<std::is_convertible<Func, const char *>,
0450 QtPrivate::Invoke::AreOldStyleArgs<Func>>,
0451 bool>
0452 invokeMethod(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
0453 Func &&function, typename QtPrivate::Callable<Func>::ReturnType *ret)
0454 {
0455 return invokeMethod(object, std::forward<Func>(function), Qt::AutoConnection, ret);
0456 }
0457
0458 template <typename Func, typename... Args>
0459 static std::enable_if_t<!std::disjunction_v<std::is_convertible<Func, const char *>,
0460 QtPrivate::Invoke::AreOldStyleArgs<Args...>>,
0461 bool>
0462 invokeMethod(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
0463 Func &&function, Qt::ConnectionType type,
0464 QTemplatedMetaMethodReturnArgument<
0465 typename QtPrivate::Callable<Func, Args...>::ReturnType>
0466 ret,
0467 Args &&...args)
0468 {
0469 return invokeMethodCallableHelper(object, std::forward<Func>(function), type, ret,
0470 std::forward<Args>(args)...);
0471 }
0472
0473 template <typename Func, typename... Args>
0474 static std::enable_if_t<!std::disjunction_v<std::is_convertible<Func, const char *>,
0475 QtPrivate::Invoke::AreOldStyleArgs<Args...>>,
0476 bool>
0477 invokeMethod(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
0478 Func &&function, Qt::ConnectionType type, Args &&...args)
0479 {
0480 using R = typename QtPrivate::Callable<Func, Args...>::ReturnType;
0481 QTemplatedMetaMethodReturnArgument<R> r{ QtPrivate::qMetaTypeInterfaceForType<R>(), nullptr,
0482 nullptr };
0483 return invokeMethod(object, std::forward<Func>(function), type, r,
0484 std::forward<Args>(args)...);
0485 }
0486
0487 template <typename Func, typename... Args>
0488 static std::enable_if_t<!std::disjunction_v<std::is_convertible<Func, const char *>,
0489 QtPrivate::Invoke::AreOldStyleArgs<Args...>>,
0490 bool>
0491 invokeMethod(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
0492 Func &&function,
0493 QTemplatedMetaMethodReturnArgument<
0494 typename QtPrivate::Callable<Func, Args...>::ReturnType>
0495 ret,
0496 Args &&...args)
0497 {
0498 return invokeMethod(object, std::forward<Func>(function), Qt::AutoConnection, ret,
0499 std::forward<Args>(args)...);
0500 }
0501
0502 template <typename Func, typename... Args>
0503 static std::enable_if_t<!std::disjunction_v<std::is_convertible<Func, const char *>,
0504 QtPrivate::Invoke::AreOldStyleArgs<Args...>>,
0505 bool>
0506 invokeMethod(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
0507 Func &&function, Args &&...args)
0508 {
0509 using R = typename QtPrivate::Callable<Func, Args...>::ReturnType;
0510 QTemplatedMetaMethodReturnArgument<R> r{ QtPrivate::qMetaTypeInterfaceForType<R>(), nullptr,
0511 nullptr };
0512 return invokeMethod(object, std::forward<Func>(function), Qt::AutoConnection, r,
0513 std::forward<Args>(args)...);
0514 }
0515
0516 #endif
0517
0518 #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
0519 QObject *newInstance(QGenericArgument val0,
0520 QGenericArgument val1 = QGenericArgument(),
0521 QGenericArgument val2 = QGenericArgument(),
0522 QGenericArgument val3 = QGenericArgument(),
0523 QGenericArgument val4 = QGenericArgument(),
0524 QGenericArgument val5 = QGenericArgument(),
0525 QGenericArgument val6 = QGenericArgument(),
0526 QGenericArgument val7 = QGenericArgument(),
0527 QGenericArgument val8 = QGenericArgument(),
0528 QGenericArgument val9 = QGenericArgument()) const;
0529 #endif
0530
0531 template <typename... Args>
0532 #ifdef Q_QDOC
0533 QObject *
0534 #else
0535 QtPrivate::Invoke::IfNotOldStyleArgs<QObject *, Args...>
0536 #endif
0537 newInstance(Args &&... arguments) const
0538 {
0539 auto h = QtPrivate::invokeMethodHelper(QMetaMethodReturnArgument{}, std::forward<Args>(arguments)...);
0540 return newInstanceImpl(this, h.parameterCount(), h.parameters.data(),
0541 h.typeNames.data(), h.metaTypes.data());
0542 }
0543
0544 enum Call {
0545 InvokeMetaMethod,
0546 ReadProperty,
0547 WriteProperty,
0548 ResetProperty,
0549 CreateInstance,
0550 IndexOfMethod,
0551 RegisterPropertyMetaType,
0552 RegisterMethodArgumentMetaType,
0553 BindableProperty,
0554 CustomCall,
0555 ConstructInPlace,
0556 };
0557
0558 int static_metacall(Call, int, void **) const;
0559 static int metacall(QObject *, Call, int, void **);
0560
0561 template <const QMetaObject &MO> static constexpr const QMetaObject *staticMetaObject()
0562 {
0563 return &MO;
0564 }
0565
0566 struct SuperData {
0567 using Getter = const QMetaObject *(*)();
0568 const QMetaObject *direct;
0569 SuperData() = default;
0570 constexpr SuperData(std::nullptr_t) : direct(nullptr) {}
0571 constexpr SuperData(const QMetaObject *mo) : direct(mo) {}
0572
0573 constexpr const QMetaObject *operator->() const { return operator const QMetaObject *(); }
0574
0575 #ifdef QT_NO_DATA_RELOCATION
0576 Getter indirect = nullptr;
0577 constexpr SuperData(Getter g) : direct(nullptr), indirect(g) {}
0578 constexpr operator const QMetaObject *() const
0579 { return indirect ? indirect() : direct; }
0580 template <const QMetaObject &MO> static constexpr SuperData link()
0581 { return SuperData(QMetaObject::staticMetaObject<MO>); }
0582 #else
0583 constexpr SuperData(Getter g) : direct(g()) {}
0584 constexpr operator const QMetaObject *() const
0585 { return direct; }
0586 template <const QMetaObject &MO> static constexpr SuperData link()
0587 { return SuperData(QMetaObject::staticMetaObject<MO>()); }
0588 #endif
0589 };
0590
0591 struct Data {
0592 SuperData superdata;
0593 const uint *stringdata;
0594 const uint *data;
0595 typedef void (*StaticMetacallFunction)(QObject *, QMetaObject::Call, int, void **);
0596 StaticMetacallFunction static_metacall;
0597 const SuperData *relatedMetaObjects;
0598 const QtPrivate::QMetaTypeInterface *const *metaTypes;
0599 void *extradata;
0600 } d;
0601
0602 private:
0603
0604
0605 template <typename Func, typename... Args>
0606 static bool
0607 invokeMethodCallableHelper(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
0608 Func &&function, Qt::ConnectionType type, const QMetaMethodReturnArgument &ret,
0609 Args &&...args)
0610 {
0611 using Callable = QtPrivate::Callable<Func, Args...>;
0612 using ExpectedArguments = typename Callable::Arguments;
0613 static_assert(sizeof...(Args) <= ExpectedArguments::size, "Too many arguments");
0614 using ActualArguments = QtPrivate::List<Args...>;
0615 static_assert(QtPrivate::CheckCompatibleArguments<ActualArguments,
0616 ExpectedArguments>::value,
0617 "Incompatible arguments");
0618
0619 auto h = QtPrivate::invokeMethodHelper(ret, std::forward<Args>(args)...);
0620
0621
0622 auto callable = new QtPrivate::QCallableObject<std::decay_t<Func>, ActualArguments,
0623 typename Callable::ReturnType>(std::forward<Func>(function));
0624 return invokeMethodImpl(object, callable, type, h.parameterCount(), h.parameters.data(),
0625 h.typeNames.data(), h.metaTypes.data());
0626 }
0627
0628 static bool invokeMethodImpl(QObject *object, const char *member, Qt::ConnectionType type,
0629 qsizetype parameterCount, const void *const *parameters, const char *const *names,
0630 const QtPrivate::QMetaTypeInterface * const *metaTypes);
0631 static bool invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *slotObj,
0632 Qt::ConnectionType type, qsizetype parameterCount,
0633 const void *const *params, const char *const *names,
0634 const QtPrivate::QMetaTypeInterface *const *metaTypes);
0635 #if QT_CORE_REMOVED_SINCE(6, 7)
0636 static bool invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *slot, Qt::ConnectionType type, void *ret);
0637 #endif
0638 static QObject *newInstanceImpl(const QMetaObject *mobj, qsizetype parameterCount,
0639 const void **parameters, const char **typeNames,
0640 const QtPrivate::QMetaTypeInterface **metaTypes);
0641 friend class QTimer;
0642 };
0643
0644 class Q_CORE_EXPORT QMetaObject::Connection {
0645 void *d_ptr;
0646 explicit Connection(void *data) : d_ptr(data) { }
0647 friend class QObject;
0648 friend class QObjectPrivate;
0649 friend struct QMetaObject;
0650 bool isConnected_helper() const;
0651 public:
0652 ~Connection();
0653 Connection();
0654 Connection(const Connection &other);
0655 Connection &operator=(const Connection &other);
0656 #ifdef Q_QDOC
0657 operator bool() const;
0658 #else
0659
0660
0661 typedef void *Connection::*RestrictedBool;
0662 operator RestrictedBool() const { return d_ptr && isConnected_helper() ? &Connection::d_ptr : nullptr; }
0663 #endif
0664
0665 Connection(Connection &&other) noexcept : d_ptr(std::exchange(other.d_ptr, nullptr)) {}
0666 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(Connection)
0667 void swap(Connection &other) noexcept { qt_ptr_swap(d_ptr, other.d_ptr); }
0668 };
0669
0670 inline void swap(QMetaObject::Connection &lhs, QMetaObject::Connection &rhs) noexcept
0671 {
0672 lhs.swap(rhs);
0673 }
0674
0675 inline const QMetaObject *QMetaObject::superClass() const
0676 { return d.superdata; }
0677
0678 namespace QtPrivate {
0679
0680 template <typename Object> struct HasQ_OBJECT_Macro {
0681 template <typename T>
0682 static char test(int (T::*)(QMetaObject::Call, int, void **));
0683 static int test(int (Object::*)(QMetaObject::Call, int, void **));
0684 enum { Value = sizeof(test(&Object::qt_metacall)) == sizeof(int) };
0685 };
0686 }
0687
0688 QT_END_NAMESPACE
0689
0690 #endif