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