File indexing completed on 2025-09-13 09:06:12
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 template <typename Ret, typename... Args> static inline void
0300 activate(QObject *sender, const QMetaObject *mo, int local_signal_index, Ret *ret, const Args &... args)
0301 {
0302 void *_a[] = {
0303 const_cast<void *>(reinterpret_cast<const volatile void *>(ret)),
0304 const_cast<void *>(reinterpret_cast<const volatile void *>(std::addressof(args)))...
0305 };
0306 activate(sender, mo, local_signal_index, _a);
0307 }
0308
0309 #if QT_VERSION <= QT_VERSION_CHECK(7, 0, 0)
0310 static bool invokeMethod(QObject *obj, const char *member,
0311 Qt::ConnectionType,
0312 QGenericReturnArgument ret,
0313 QGenericArgument val0 = QGenericArgument(nullptr),
0314 QGenericArgument val1 = QGenericArgument(),
0315 QGenericArgument val2 = QGenericArgument(),
0316 QGenericArgument val3 = QGenericArgument(),
0317 QGenericArgument val4 = QGenericArgument(),
0318 QGenericArgument val5 = QGenericArgument(),
0319 QGenericArgument val6 = QGenericArgument(),
0320 QGenericArgument val7 = QGenericArgument(),
0321 QGenericArgument val8 = QGenericArgument(),
0322 QGenericArgument val9 = QGenericArgument());
0323
0324 static inline bool invokeMethod(QObject *obj, const char *member,
0325 QGenericReturnArgument ret,
0326 QGenericArgument val0 = QGenericArgument(nullptr),
0327 QGenericArgument val1 = QGenericArgument(),
0328 QGenericArgument val2 = QGenericArgument(),
0329 QGenericArgument val3 = QGenericArgument(),
0330 QGenericArgument val4 = QGenericArgument(),
0331 QGenericArgument val5 = QGenericArgument(),
0332 QGenericArgument val6 = QGenericArgument(),
0333 QGenericArgument val7 = QGenericArgument(),
0334 QGenericArgument val8 = QGenericArgument(),
0335 QGenericArgument val9 = QGenericArgument())
0336 {
0337 return invokeMethod(obj, member, Qt::AutoConnection, ret, val0, val1, val2, val3,
0338 val4, val5, val6, val7, val8, val9);
0339 }
0340
0341 static inline bool invokeMethod(QObject *obj, const char *member,
0342 Qt::ConnectionType type,
0343 QGenericArgument val0,
0344 QGenericArgument val1 = QGenericArgument(),
0345 QGenericArgument val2 = QGenericArgument(),
0346 QGenericArgument val3 = QGenericArgument(),
0347 QGenericArgument val4 = QGenericArgument(),
0348 QGenericArgument val5 = QGenericArgument(),
0349 QGenericArgument val6 = QGenericArgument(),
0350 QGenericArgument val7 = QGenericArgument(),
0351 QGenericArgument val8 = QGenericArgument(),
0352 QGenericArgument val9 = QGenericArgument())
0353 {
0354 return invokeMethod(obj, member, type, QGenericReturnArgument(), val0, val1, val2,
0355 val3, val4, val5, val6, val7, val8, val9);
0356 }
0357
0358 static inline bool invokeMethod(QObject *obj, const char *member,
0359 QGenericArgument val0,
0360 QGenericArgument val1 = QGenericArgument(),
0361 QGenericArgument val2 = QGenericArgument(),
0362 QGenericArgument val3 = QGenericArgument(),
0363 QGenericArgument val4 = QGenericArgument(),
0364 QGenericArgument val5 = QGenericArgument(),
0365 QGenericArgument val6 = QGenericArgument(),
0366 QGenericArgument val7 = QGenericArgument(),
0367 QGenericArgument val8 = QGenericArgument(),
0368 QGenericArgument val9 = QGenericArgument())
0369 {
0370 return invokeMethod(obj, member, Qt::AutoConnection, QGenericReturnArgument(), val0,
0371 val1, val2, val3, val4, val5, val6, val7, val8, val9);
0372 }
0373 #endif
0374
0375 template <typename ReturnArg, typename... Args> static
0376 #ifdef Q_QDOC
0377 bool
0378 #else
0379 QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...>
0380 #endif
0381 invokeMethod(QObject *obj, const char *member, Qt::ConnectionType c,
0382 QTemplatedMetaMethodReturnArgument<ReturnArg> r, Args &&... arguments)
0383 {
0384 auto h = QtPrivate::invokeMethodHelper(r, std::forward<Args>(arguments)...);
0385 return invokeMethodImpl(obj, member, c, h.parameterCount(), h.parameters.data(),
0386 h.typeNames.data(), h.metaTypes.data());
0387 }
0388
0389 template <typename... Args> static
0390 #ifdef Q_QDOC
0391 bool
0392 #else
0393 QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...>
0394 #endif
0395 invokeMethod(QObject *obj, const char *member, Qt::ConnectionType c, Args &&... arguments)
0396 {
0397 QTemplatedMetaMethodReturnArgument<void> r = {};
0398 return invokeMethod(obj, member, c, r, std::forward<Args>(arguments)...);
0399 }
0400
0401 template <typename ReturnArg, typename... Args> static
0402 #ifdef Q_QDOC
0403 bool
0404 #else
0405 QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...>
0406 #endif
0407 invokeMethod(QObject *obj, const char *member, QTemplatedMetaMethodReturnArgument<ReturnArg> r,
0408 Args &&... arguments)
0409 {
0410 return invokeMethod(obj, member, Qt::AutoConnection, r, std::forward<Args>(arguments)...);
0411 }
0412
0413 template <typename... Args> static
0414 #ifdef Q_QDOC
0415 bool
0416 #else
0417 QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...>
0418 #endif
0419 invokeMethod(QObject *obj, const char *member, Args &&... arguments)
0420 {
0421 QTemplatedMetaMethodReturnArgument<void> r = {};
0422 return invokeMethod(obj, member, Qt::AutoConnection, r, std::forward<Args>(arguments)...);
0423 }
0424
0425 #ifdef Q_QDOC
0426 template<typename Functor, typename FunctorReturnType>
0427 static bool invokeMethod(QObject *context, Functor &&function, Qt::ConnectionType type = Qt::AutoConnection, FunctorReturnType *ret = nullptr);
0428 template<typename Functor, typename FunctorReturnType>
0429 static bool invokeMethod(QObject *context, Functor &&function, FunctorReturnType *ret);
0430
0431 template<typename Functor, typename FunctorReturnType, typename... Args>
0432 static bool invokeMethod(QObject *context, Functor &&function, Qt::ConnectionType type, QTemplatedMetaMethodReturnArgument<FunctorReturnType> ret, Args &&...arguments);
0433 template<typename Functor, typename FunctorReturnType, typename... Args>
0434 static bool invokeMethod(QObject *context, Functor &&function, QTemplatedMetaMethodReturnArgument<FunctorReturnType> ret, Args &&...arguments);
0435 template<typename Functor, typename... Args>
0436 static bool invokeMethod(QObject *context, Functor &&function, Qt::ConnectionType type, Args &&...arguments);
0437 template<typename Functor, typename... Args>
0438 static bool invokeMethod(QObject *context, Functor &&function, Args &&...arguments);
0439 #else
0440 template <typename Func>
0441 static std::enable_if_t<!std::disjunction_v<std::is_convertible<Func, const char *>,
0442 QtPrivate::Invoke::AreOldStyleArgs<Func>>,
0443 bool>
0444 invokeMethod(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
0445 Func &&function, Qt::ConnectionType type,
0446 typename QtPrivate::Callable<Func>::ReturnType *ret)
0447 {
0448 using R = typename QtPrivate::Callable<Func>::ReturnType;
0449 const auto getReturnArg = [ret]() -> QTemplatedMetaMethodReturnArgument<R> {
0450 if constexpr (std::is_void_v<R>)
0451 return {};
0452 else
0453 return ret ? qReturnArg(*ret) : QTemplatedMetaMethodReturnArgument<R>{};
0454 };
0455 return invokeMethod(object, std::forward<Func>(function), type, getReturnArg());
0456 }
0457 template <typename Func>
0458 static std::enable_if_t<!std::disjunction_v<std::is_convertible<Func, const char *>,
0459 QtPrivate::Invoke::AreOldStyleArgs<Func>>,
0460 bool>
0461 invokeMethod(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
0462 Func &&function, typename QtPrivate::Callable<Func>::ReturnType *ret)
0463 {
0464 return invokeMethod(object, std::forward<Func>(function), Qt::AutoConnection, ret);
0465 }
0466
0467 template <typename Func, typename... Args>
0468 static std::enable_if_t<!std::disjunction_v<std::is_convertible<Func, const char *>,
0469 QtPrivate::Invoke::AreOldStyleArgs<Args...>>,
0470 bool>
0471 invokeMethod(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
0472 Func &&function, Qt::ConnectionType type,
0473 QTemplatedMetaMethodReturnArgument<
0474 typename QtPrivate::Callable<Func, Args...>::ReturnType>
0475 ret,
0476 Args &&...args)
0477 {
0478 return invokeMethodCallableHelper(object, std::forward<Func>(function), type, ret,
0479 std::forward<Args>(args)...);
0480 }
0481
0482 template <typename Func, typename... Args>
0483 static std::enable_if_t<!std::disjunction_v<std::is_convertible<Func, const char *>,
0484 QtPrivate::Invoke::AreOldStyleArgs<Args...>>,
0485 bool>
0486 invokeMethod(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
0487 Func &&function, Qt::ConnectionType type, Args &&...args)
0488 {
0489 using R = typename QtPrivate::Callable<Func, Args...>::ReturnType;
0490 QTemplatedMetaMethodReturnArgument<R> r{ QtPrivate::qMetaTypeInterfaceForType<R>(), nullptr,
0491 nullptr };
0492 return invokeMethod(object, std::forward<Func>(function), type, r,
0493 std::forward<Args>(args)...);
0494 }
0495
0496 template <typename Func, typename... Args>
0497 static std::enable_if_t<!std::disjunction_v<std::is_convertible<Func, const char *>,
0498 QtPrivate::Invoke::AreOldStyleArgs<Args...>>,
0499 bool>
0500 invokeMethod(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
0501 Func &&function,
0502 QTemplatedMetaMethodReturnArgument<
0503 typename QtPrivate::Callable<Func, Args...>::ReturnType>
0504 ret,
0505 Args &&...args)
0506 {
0507 return invokeMethod(object, std::forward<Func>(function), Qt::AutoConnection, ret,
0508 std::forward<Args>(args)...);
0509 }
0510
0511 template <typename Func, typename... Args>
0512 static std::enable_if_t<!std::disjunction_v<std::is_convertible<Func, const char *>,
0513 QtPrivate::Invoke::AreOldStyleArgs<Args...>>,
0514 bool>
0515 invokeMethod(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
0516 Func &&function, Args &&...args)
0517 {
0518 using R = typename QtPrivate::Callable<Func, Args...>::ReturnType;
0519 QTemplatedMetaMethodReturnArgument<R> r{ QtPrivate::qMetaTypeInterfaceForType<R>(), nullptr,
0520 nullptr };
0521 return invokeMethod(object, std::forward<Func>(function), Qt::AutoConnection, r,
0522 std::forward<Args>(args)...);
0523 }
0524
0525 #endif
0526
0527 #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
0528 QObject *newInstance(QGenericArgument val0,
0529 QGenericArgument val1 = QGenericArgument(),
0530 QGenericArgument val2 = QGenericArgument(),
0531 QGenericArgument val3 = QGenericArgument(),
0532 QGenericArgument val4 = QGenericArgument(),
0533 QGenericArgument val5 = QGenericArgument(),
0534 QGenericArgument val6 = QGenericArgument(),
0535 QGenericArgument val7 = QGenericArgument(),
0536 QGenericArgument val8 = QGenericArgument(),
0537 QGenericArgument val9 = QGenericArgument()) const;
0538 #endif
0539
0540 template <typename... Args>
0541 #ifdef Q_QDOC
0542 QObject *
0543 #else
0544 QtPrivate::Invoke::IfNotOldStyleArgs<QObject *, Args...>
0545 #endif
0546 newInstance(Args &&... arguments) const
0547 {
0548 auto h = QtPrivate::invokeMethodHelper(QMetaMethodReturnArgument{}, std::forward<Args>(arguments)...);
0549 return newInstanceImpl(this, h.parameterCount(), h.parameters.data(),
0550 h.typeNames.data(), h.metaTypes.data());
0551 }
0552
0553 enum Call {
0554 InvokeMetaMethod,
0555 ReadProperty,
0556 WriteProperty,
0557 ResetProperty,
0558 CreateInstance,
0559 IndexOfMethod,
0560 RegisterPropertyMetaType,
0561 RegisterMethodArgumentMetaType,
0562 BindableProperty,
0563 CustomCall,
0564 ConstructInPlace,
0565 };
0566
0567 int static_metacall(Call, int, void **) const;
0568 static int metacall(QObject *, Call, int, void **);
0569
0570 template <const QMetaObject &MO> static constexpr const QMetaObject *staticMetaObject()
0571 {
0572 return &MO;
0573 }
0574
0575 struct SuperData {
0576 using Getter = const QMetaObject *(*)();
0577 const QMetaObject *direct;
0578 SuperData() = default;
0579 constexpr SuperData(std::nullptr_t) : direct(nullptr) {}
0580 constexpr SuperData(const QMetaObject *mo) : direct(mo) {}
0581
0582 constexpr const QMetaObject *operator->() const { return operator const QMetaObject *(); }
0583
0584 #ifdef QT_NO_DATA_RELOCATION
0585 Getter indirect = nullptr;
0586 constexpr SuperData(Getter g) : direct(nullptr), indirect(g) {}
0587 constexpr operator const QMetaObject *() const
0588 { return indirect ? indirect() : direct; }
0589 template <const QMetaObject &MO> static constexpr SuperData link()
0590 { return SuperData(QMetaObject::staticMetaObject<MO>); }
0591 #else
0592 constexpr SuperData(Getter g) : direct(g()) {}
0593 constexpr operator const QMetaObject *() const
0594 { return direct; }
0595 template <const QMetaObject &MO> static constexpr SuperData link()
0596 { return SuperData(QMetaObject::staticMetaObject<MO>()); }
0597 #endif
0598 };
0599
0600 struct Data {
0601 SuperData superdata;
0602 const uint *stringdata;
0603 const uint *data;
0604 typedef void (*StaticMetacallFunction)(QObject *, QMetaObject::Call, int, void **);
0605 StaticMetacallFunction static_metacall;
0606 const SuperData *relatedMetaObjects;
0607 const QtPrivate::QMetaTypeInterface *const *metaTypes;
0608 void *extradata;
0609 } d;
0610
0611 private:
0612
0613
0614 template <typename Func, typename... Args>
0615 static bool
0616 invokeMethodCallableHelper(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
0617 Func &&function, Qt::ConnectionType type, const QMetaMethodReturnArgument &ret,
0618 Args &&...args)
0619 {
0620 using Callable = QtPrivate::Callable<Func, Args...>;
0621 using ExpectedArguments = typename Callable::Arguments;
0622 static_assert(sizeof...(Args) <= ExpectedArguments::size, "Too many arguments");
0623 using ActualArguments = QtPrivate::List<Args...>;
0624 static_assert(QtPrivate::CheckCompatibleArguments<ActualArguments,
0625 ExpectedArguments>::value,
0626 "Incompatible arguments");
0627
0628 auto h = QtPrivate::invokeMethodHelper(ret, std::forward<Args>(args)...);
0629
0630
0631 auto callable = new QtPrivate::QCallableObject<std::decay_t<Func>, ActualArguments,
0632 typename Callable::ReturnType>(std::forward<Func>(function));
0633 return invokeMethodImpl(object, callable, type, h.parameterCount(), h.parameters.data(),
0634 h.typeNames.data(), h.metaTypes.data());
0635 }
0636
0637 static bool invokeMethodImpl(QObject *object, const char *member, Qt::ConnectionType type,
0638 qsizetype parameterCount, const void *const *parameters, const char *const *names,
0639 const QtPrivate::QMetaTypeInterface * const *metaTypes);
0640 static bool invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *slotObj,
0641 Qt::ConnectionType type, qsizetype parameterCount,
0642 const void *const *params, const char *const *names,
0643 const QtPrivate::QMetaTypeInterface *const *metaTypes);
0644 #if QT_CORE_REMOVED_SINCE(6, 7)
0645 static bool invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *slot, Qt::ConnectionType type, void *ret);
0646 #endif
0647 static QObject *newInstanceImpl(const QMetaObject *mobj, qsizetype parameterCount,
0648 const void **parameters, const char **typeNames,
0649 const QtPrivate::QMetaTypeInterface **metaTypes);
0650 friend class QTimer;
0651 friend class QChronoTimer;
0652 };
0653
0654 class Q_CORE_EXPORT QMetaObject::Connection {
0655 void *d_ptr;
0656 explicit Connection(void *data) : d_ptr(data) { }
0657 friend class QObject;
0658 friend class QObjectPrivate;
0659 friend struct QMetaObject;
0660 bool isConnected_helper() const;
0661 public:
0662 ~Connection();
0663 Connection();
0664 Connection(const Connection &other);
0665 Connection &operator=(const Connection &other);
0666 #ifdef Q_QDOC
0667 operator bool() const;
0668 #else
0669
0670
0671 typedef void *Connection::*RestrictedBool;
0672 operator RestrictedBool() const { return d_ptr && isConnected_helper() ? &Connection::d_ptr : nullptr; }
0673 #endif
0674
0675 Connection(Connection &&other) noexcept : d_ptr(std::exchange(other.d_ptr, nullptr)) {}
0676 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(Connection)
0677 void swap(Connection &other) noexcept { qt_ptr_swap(d_ptr, other.d_ptr); }
0678 };
0679
0680 inline void swap(QMetaObject::Connection &lhs, QMetaObject::Connection &rhs) noexcept
0681 {
0682 lhs.swap(rhs);
0683 }
0684
0685 inline const QMetaObject *QMetaObject::superClass() const
0686 { return d.superdata; }
0687
0688 namespace QtPrivate {
0689
0690 template <typename Object> struct HasQ_OBJECT_Macro {
0691 template <typename T>
0692 static char test(int (T::*)(QMetaObject::Call, int, void **));
0693 static int test(int (Object::*)(QMetaObject::Call, int, void **));
0694 enum { Value = sizeof(test(&Object::qt_metacall)) == sizeof(int) };
0695 };
0696 }
0697
0698 QT_END_NAMESPACE
0699
0700 #endif