Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qobjectdefs.h
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// Copyright (C) 2019 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6#ifndef QOBJECTDEFS_H
7#define QOBJECTDEFS_H
8
9#if defined(__OBJC__) && !defined(__cplusplus)
10# warning "File built in Objective-C mode (.m), but using Qt requires Objective-C++ (.mm)"
11#endif
12
13#include <QtCore/qnamespace.h>
14#include <QtCore/qobjectdefs_impl.h>
15#include <QtCore/qtcoreexports.h>
16#include <QtCore/qtmetamacros.h>
17
19
20class QByteArray;
21struct QArrayData;
22
23class QString;
24
25#ifndef QT_NO_META_MACROS
26// macro for onaming members
27#ifdef METHOD
28#undef METHOD
29#endif
30#ifdef SLOT
31#undef SLOT
32#endif
33#ifdef SIGNAL
34#undef SIGNAL
35#endif
36#endif // QT_NO_META_MACROS
37
38Q_CORE_EXPORT const char *qFlagLocation(const char *method);
39
40#ifndef QT_NO_META_MACROS
41# define QMETHOD_CODE 0 // member type codes
42# define QSLOT_CODE 1
43# define QSIGNAL_CODE 2
44# define QT_PREFIX_CODE(code, a) QT_STRINGIFY(code) #a
45# define QT_STRINGIFY_METHOD(a) QT_PREFIX_CODE(QMETHOD_CODE, a)
46# define QT_STRINGIFY_SLOT(a) QT_PREFIX_CODE(QSLOT_CODE, a)
47# define QT_STRINGIFY_SIGNAL(a) QT_PREFIX_CODE(QSIGNAL_CODE, a)
48# ifndef QT_NO_DEBUG
49# define QLOCATION "\0" __FILE__ ":" QT_STRINGIFY(__LINE__)
50# ifndef QT_NO_KEYWORDS
51# define METHOD(a) qFlagLocation(QT_STRINGIFY_METHOD(a) QLOCATION)
52# endif
53# define SLOT(a) qFlagLocation(QT_STRINGIFY_SLOT(a) QLOCATION)
54# define SIGNAL(a) qFlagLocation(QT_STRINGIFY_SIGNAL(a) QLOCATION)
55# else
56# ifndef QT_NO_KEYWORDS
57# define METHOD(a) QT_STRINGIFY_METHOD(a)
58# endif
59# define SLOT(a) QT_STRINGIFY_SLOT(a)
60# define SIGNAL(a) QT_STRINGIFY_SIGNAL(a)
61# endif
62#endif // QT_NO_META_MACROS
63
64#define Q_ARG(Type, data) QtPrivate::Invoke::argument<Type>(QT_STRINGIFY(Type), data)
65#define Q_RETURN_ARG(Type, data) QtPrivate::Invoke::returnArgument<Type>(QT_STRINGIFY(Type), data)
66
67class QObject;
68class QMetaMethod;
69class QMetaEnum;
70class QMetaProperty;
71class QMetaClassInfo;
72
73namespace QtPrivate {
75template<typename T> constexpr const QMetaTypeInterface *qMetaTypeInterfaceForType();
76}
77
79{
80 void **arguments;
81};
82
83#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
84class Q_CORE_EXPORT QGenericArgument
85{
86public:
87 inline QGenericArgument(const char *aName = nullptr, const void *aData = nullptr)
88 : _data(aData), _name(aName) {}
89 inline void *data() const { return const_cast<void *>(_data); }
90 inline const char *name() const { return _name; }
91
92private:
93 const void *_data;
94 const char *_name;
95};
96
97class Q_CORE_EXPORT QGenericReturnArgument: public QGenericArgument
98{
99public:
100 inline QGenericReturnArgument(const char *aName = nullptr, void *aData = nullptr)
101 : QGenericArgument(aName, aData)
102 {}
103};
104
105template <class T>
106class QArgument: public QGenericArgument
107{
108public:
109 inline QArgument(const char *aName, const T &aData)
110 : QGenericArgument(aName, static_cast<const void *>(&aData))
111 {}
112};
113template <class T>
114class QArgument<T &>: public QGenericArgument
115{
116public:
117 inline QArgument(const char *aName, T &aData)
118 : QGenericArgument(aName, static_cast<const void *>(&aData))
119 {}
120};
121
122
123template <typename T>
124class QReturnArgument: public QGenericReturnArgument
125{
126public:
127 inline QReturnArgument(const char *aName, T &aData)
128 : QGenericReturnArgument(aName, static_cast<void *>(&aData))
129 {}
130};
131#endif
132
134{
136 const char *name;
137 const void *data;
138};
139
146
147template <typename T>
152
153namespace QtPrivate {
154namespace Invoke {
155#if QT_VERSION <= QT_VERSION_CHECK(7, 0, 0)
156template <typename... Args>
158
159template <typename T, typename... Args> using IfNotOldStyleArgs =
161#else
162template <typename T, typename... Args> using IfNotOldStyleArgs = T;
163#endif
164
165template <typename T> inline QMetaMethodArgument argument(const char *name, const T &t)
166{
167 if constexpr ((std::is_lvalue_reference_v<T> && std::is_const_v<std::remove_reference_t<T>>) ||
168 !std::is_reference_v<T>) {
169 return { qMetaTypeInterfaceForType<T>(), name, std::addressof(t) };
170 } else {
171 return { nullptr, name, std::addressof(t) };
172 }
173}
174
175template <typename T>
176inline QTemplatedMetaMethodReturnArgument<T> returnArgument(const char *name, T &t)
177{
178 return { qMetaTypeInterfaceForType<T>(), name, std::addressof(t) };
179}
180
181template <typename T> inline const char *typenameHelper(const T &)
182{
183 return nullptr;
184}
185template <typename T> inline const void *dataHelper(const T &t)
186{
187 return std::addressof(t);
188}
189template <typename T> inline const QMetaTypeInterface *metaTypeHelper(const T &)
190{
191 return qMetaTypeInterfaceForType<T>();
192}
193
195{ return a.name; }
196inline const void *dataHelper(QMetaMethodArgument a)
197{ return a.data; }
200
201inline const char *typenameHelper(const char *) = delete;
202template <typename T> inline const void *dataHelper(const char *) = delete;
203inline const QMetaTypeInterface *metaTypeHelper(const char *) = delete;
204inline const char *typenameHelper(const char16_t *) = delete;
205template <typename T> inline const void *dataHelper(const char16_t *) = delete;
206inline const QMetaTypeInterface *metaTypeHelper(const char16_t *) = delete;
207
208} // namespace QtPrivate::Invoke
209
210template <typename... Args> inline auto invokeMethodHelper(QMetaMethodReturnArgument r, const Args &... arguments)
211{
212 std::array params = { const_cast<const void *>(r.data), Invoke::dataHelper(arguments)... };
213 std::array names = { r.name, Invoke::typenameHelper(arguments)... };
214 std::array types = { r.metaType, Invoke::metaTypeHelper(arguments)... };
215 static_assert(params.size() == types.size());
216 static_assert(params.size() == names.size());
217
218 struct R {
219 decltype(params) parameters;
220 decltype(names) typeNames;
221 decltype(types) metaTypes;
222 constexpr qsizetype parameterCount() const { return qsizetype(parameters.size()); }
223 };
224 return R { params, names, types };
225}
226} // namespace QtPrivate
227
228template <typename T> void qReturnArg(const T &&) = delete;
229template <typename T> inline QTemplatedMetaMethodReturnArgument<T> qReturnArg(T &data)
230{
231 return QtPrivate::Invoke::returnArgument(nullptr, data);
232}
233
234struct Q_CORE_EXPORT QMetaObject
235{
236 class Connection;
237 const char *className() const;
238 const QMetaObject *superClass() const;
239
240 bool inherits(const QMetaObject *metaObject) const noexcept;
241 QObject *cast(QObject *obj) const
242 { return const_cast<QObject *>(cast(const_cast<const QObject *>(obj))); }
243 const QObject *cast(const QObject *obj) const;
244
245#if !defined(QT_NO_TRANSLATION) || defined(Q_QDOC)
246 QString tr(const char *s, const char *c, int n = -1) const;
247#endif // QT_NO_TRANSLATION
248
249 QMetaType metaType() const;
250
251 int methodOffset() const;
252 int enumeratorOffset() const;
253 int propertyOffset() const;
254 int classInfoOffset() const;
255
256 int constructorCount() const;
257 int methodCount() const;
258 int enumeratorCount() const;
259 int propertyCount() const;
260 int classInfoCount() const;
261
262 int indexOfConstructor(const char *constructor) const;
263 int indexOfMethod(const char *method) const;
264 int indexOfSignal(const char *signal) const;
265 int indexOfSlot(const char *slot) const;
266 int indexOfEnumerator(const char *name) const;
267
268 int indexOfProperty(const char *name) const;
269 int indexOfClassInfo(const char *name) const;
270
271 QMetaMethod constructor(int index) const;
272 QMetaMethod method(int index) const;
273 QMetaEnum enumerator(int index) const;
274 QMetaProperty property(int index) const;
275 QMetaClassInfo classInfo(int index) const;
276 QMetaProperty userProperty() const;
277
278 static bool checkConnectArgs(const char *signal, const char *method);
279 static bool checkConnectArgs(const QMetaMethod &signal,
280 const QMetaMethod &method);
281 static QByteArray normalizedSignature(const char *method);
282 static QByteArray normalizedType(const char *type);
283
284 // internal index-based connect
285 static Connection connect(const QObject *sender, int signal_index,
286 const QObject *receiver, int method_index,
287 int type = 0, int *types = nullptr);
288 // internal index-based disconnect
289 static bool disconnect(const QObject *sender, int signal_index,
290 const QObject *receiver, int method_index);
291 static bool disconnectOne(const QObject *sender, int signal_index,
292 const QObject *receiver, int method_index);
293 // internal slot-name based connect
294 static void connectSlotsByName(QObject *o);
295
296#ifdef Q_QDOC
297 template<typename PointerToMemberFunction>
298 static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type = Qt::AutoConnection);
299 template<typename Functor>
300 static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal, const QObject *context, Functor functor, Qt::ConnectionType type = Qt::AutoConnection);
301#else
302 template <typename Func>
303 static inline Connection
304 connect(const QObject *sender, const QMetaMethod &signal,
305 const typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *context, Func &&slot,
306 Qt::ConnectionType type = Qt::AutoConnection);
307#endif // Q_QDOC
308
309 // internal index-based signal activation
310 static void activate(QObject *sender, int signal_index, void **argv);
311 static void activate(QObject *sender, const QMetaObject *, int local_signal_index, void **argv);
312 static void activate(QObject *sender, int signal_offset, int local_signal_index, void **argv);
313 template <typename Ret, typename... Args> static inline void
314 activate(QObject *sender, const QMetaObject *mo, int local_signal_index, Ret *ret, const Args &... args)
315 {
316 void *_a[] = {
317 const_cast<void *>(reinterpret_cast<const volatile void *>(ret)),
318 const_cast<void *>(reinterpret_cast<const volatile void *>(std::addressof(args)))...
319 };
320 activate(sender, mo, local_signal_index, _a);
321 }
322
323#if QT_VERSION <= QT_VERSION_CHECK(7, 0, 0)
324 static bool invokeMethod(QObject *obj, const char *member,
325 Qt::ConnectionType,
326 QGenericReturnArgument ret,
327 QGenericArgument val0 = QGenericArgument(nullptr),
328 QGenericArgument val1 = QGenericArgument(),
329 QGenericArgument val2 = QGenericArgument(),
330 QGenericArgument val3 = QGenericArgument(),
331 QGenericArgument val4 = QGenericArgument(),
332 QGenericArgument val5 = QGenericArgument(),
333 QGenericArgument val6 = QGenericArgument(),
334 QGenericArgument val7 = QGenericArgument(),
335 QGenericArgument val8 = QGenericArgument(),
336 QGenericArgument val9 = QGenericArgument());
337
338 static inline bool invokeMethod(QObject *obj, const char *member,
339 QGenericReturnArgument ret,
340 QGenericArgument val0 = QGenericArgument(nullptr),
341 QGenericArgument val1 = QGenericArgument(),
342 QGenericArgument val2 = QGenericArgument(),
343 QGenericArgument val3 = QGenericArgument(),
344 QGenericArgument val4 = QGenericArgument(),
345 QGenericArgument val5 = QGenericArgument(),
346 QGenericArgument val6 = QGenericArgument(),
347 QGenericArgument val7 = QGenericArgument(),
348 QGenericArgument val8 = QGenericArgument(),
349 QGenericArgument val9 = QGenericArgument())
350 {
351 return invokeMethod(obj, member, Qt::AutoConnection, ret, val0, val1, val2, val3,
352 val4, val5, val6, val7, val8, val9);
353 }
354
355 static inline bool invokeMethod(QObject *obj, const char *member,
356 Qt::ConnectionType type,
357 QGenericArgument val0,
358 QGenericArgument val1 = QGenericArgument(),
359 QGenericArgument val2 = QGenericArgument(),
360 QGenericArgument val3 = QGenericArgument(),
361 QGenericArgument val4 = QGenericArgument(),
362 QGenericArgument val5 = QGenericArgument(),
363 QGenericArgument val6 = QGenericArgument(),
364 QGenericArgument val7 = QGenericArgument(),
365 QGenericArgument val8 = QGenericArgument(),
366 QGenericArgument val9 = QGenericArgument())
367 {
368 return invokeMethod(obj, member, type, QGenericReturnArgument(), val0, val1, val2,
369 val3, val4, val5, val6, val7, val8, val9);
370 }
371
372 static inline bool invokeMethod(QObject *obj, const char *member,
373 QGenericArgument val0,
374 QGenericArgument val1 = QGenericArgument(),
375 QGenericArgument val2 = QGenericArgument(),
376 QGenericArgument val3 = QGenericArgument(),
377 QGenericArgument val4 = QGenericArgument(),
378 QGenericArgument val5 = QGenericArgument(),
379 QGenericArgument val6 = QGenericArgument(),
380 QGenericArgument val7 = QGenericArgument(),
381 QGenericArgument val8 = QGenericArgument(),
382 QGenericArgument val9 = QGenericArgument())
383 {
384 return invokeMethod(obj, member, Qt::AutoConnection, QGenericReturnArgument(), val0,
385 val1, val2, val3, val4, val5, val6, val7, val8, val9);
386 }
387#endif // Qt < 7.0
388
389 template <typename ReturnArg, typename... Args> static
390#ifdef Q_QDOC
391 bool
392#else
393 QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...>
394#endif
395 invokeMethod(QObject *obj, const char *member, Qt::ConnectionType c,
396 QTemplatedMetaMethodReturnArgument<ReturnArg> r, Args &&... arguments)
397 {
398 auto h = QtPrivate::invokeMethodHelper(r, std::forward<Args>(arguments)...);
399 return invokeMethodImpl(obj, member, c, h.parameterCount(), h.parameters.data(),
400 h.typeNames.data(), h.metaTypes.data());
401 }
402
403 template <typename... Args> static
404#ifdef Q_QDOC
405 bool
406#else
407 QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...>
408#endif
409 invokeMethod(QObject *obj, const char *member, Qt::ConnectionType c, Args &&... arguments)
410 {
411 QTemplatedMetaMethodReturnArgument<void> r = {};
412 return invokeMethod(obj, member, c, r, std::forward<Args>(arguments)...);
413 }
414
415 template <typename ReturnArg, typename... Args> static
416#ifdef Q_QDOC
417 bool
418#else
419 QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...>
420#endif
421 invokeMethod(QObject *obj, const char *member, QTemplatedMetaMethodReturnArgument<ReturnArg> r,
422 Args &&... arguments)
423 {
424 return invokeMethod(obj, member, Qt::AutoConnection, r, std::forward<Args>(arguments)...);
425 }
426
427 template <typename... Args> static
428#ifdef Q_QDOC
429 bool
430#else
431 QtPrivate::Invoke::IfNotOldStyleArgs<bool, Args...>
432#endif
433 invokeMethod(QObject *obj, const char *member, Args &&... arguments)
434 {
435 QTemplatedMetaMethodReturnArgument<void> r = {};
436 return invokeMethod(obj, member, Qt::AutoConnection, r, std::forward<Args>(arguments)...);
437 }
438
439#ifdef Q_QDOC
440 template<typename Functor, typename FunctorReturnType>
441 static bool invokeMethod(QObject *context, Functor &&function, Qt::ConnectionType type = Qt::AutoConnection, FunctorReturnType *ret = nullptr);
442 template<typename Functor, typename FunctorReturnType>
443 static bool invokeMethod(QObject *context, Functor &&function, FunctorReturnType *ret);
444
445 template<typename Functor, typename FunctorReturnType, typename... Args>
446 static bool invokeMethod(QObject *context, Functor &&function, Qt::ConnectionType type, QTemplatedMetaMethodReturnArgument<FunctorReturnType> ret, Args &&...arguments);
447 template<typename Functor, typename FunctorReturnType, typename... Args>
448 static bool invokeMethod(QObject *context, Functor &&function, QTemplatedMetaMethodReturnArgument<FunctorReturnType> ret, Args &&...arguments);
449 template<typename Functor, typename... Args>
450 static bool invokeMethod(QObject *context, Functor &&function, Qt::ConnectionType type, Args &&...arguments);
451 template<typename Functor, typename... Args>
452 static bool invokeMethod(QObject *context, Functor &&function, Args &&...arguments);
453#else
454 template <typename Func>
455 static std::enable_if_t<!std::disjunction_v<std::is_convertible<Func, const char *>,
456 QtPrivate::Invoke::AreOldStyleArgs<Func>>,
457 bool>
458 invokeMethod(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
459 Func &&function, Qt::ConnectionType type,
460 typename QtPrivate::Callable<Func>::ReturnType *ret)
461 {
462 using R = typename QtPrivate::Callable<Func>::ReturnType;
463 const auto getReturnArg = [ret]() -> QTemplatedMetaMethodReturnArgument<R> {
464 if constexpr (std::is_void_v<R>)
465 return {};
466 else
467 return ret ? qReturnArg(*ret) : QTemplatedMetaMethodReturnArgument<R>{};
468 };
469 return invokeMethod(object, std::forward<Func>(function), type, getReturnArg());
470 }
471 template <typename Func>
472 static std::enable_if_t<!std::disjunction_v<std::is_convertible<Func, const char *>,
473 QtPrivate::Invoke::AreOldStyleArgs<Func>>,
474 bool>
475 invokeMethod(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
476 Func &&function, typename QtPrivate::Callable<Func>::ReturnType *ret)
477 {
478 return invokeMethod(object, std::forward<Func>(function), Qt::AutoConnection, ret);
479 }
480
481 template <typename Func, typename... Args>
482 static std::enable_if_t<!std::disjunction_v<std::is_convertible<Func, const char *>,
483 QtPrivate::Invoke::AreOldStyleArgs<Args...>>,
484 bool>
485 invokeMethod(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
486 Func &&function, Qt::ConnectionType type,
487 QTemplatedMetaMethodReturnArgument<
488 typename QtPrivate::Callable<Func, Args...>::ReturnType>
489 ret,
490 Args &&...args)
491 {
492 return invokeMethodCallableHelper(object, std::forward<Func>(function), type, ret,
493 std::forward<Args>(args)...);
494 }
495
496 template <typename Func, typename... Args>
497 static std::enable_if_t<!std::disjunction_v<std::is_convertible<Func, const char *>,
498 QtPrivate::Invoke::AreOldStyleArgs<Args...>>,
499 bool>
500 invokeMethod(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
501 Func &&function, Qt::ConnectionType type, Args &&...args)
502 {
503 using R = typename QtPrivate::Callable<Func, Args...>::ReturnType;
504 QTemplatedMetaMethodReturnArgument<R> r{ QtPrivate::qMetaTypeInterfaceForType<R>(), nullptr,
505 nullptr };
506 return invokeMethod(object, std::forward<Func>(function), type, r,
507 std::forward<Args>(args)...);
508 }
509
510 template <typename Func, typename... Args>
511 static std::enable_if_t<!std::disjunction_v<std::is_convertible<Func, const char *>,
512 QtPrivate::Invoke::AreOldStyleArgs<Args...>>,
513 bool>
514 invokeMethod(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
515 Func &&function,
516 QTemplatedMetaMethodReturnArgument<
517 typename QtPrivate::Callable<Func, Args...>::ReturnType>
518 ret,
519 Args &&...args)
520 {
521 return invokeMethod(object, std::forward<Func>(function), Qt::AutoConnection, ret,
522 std::forward<Args>(args)...);
523 }
524
525 template <typename Func, typename... Args>
526 static std::enable_if_t<!std::disjunction_v<std::is_convertible<Func, const char *>,
527 QtPrivate::Invoke::AreOldStyleArgs<Args...>>,
528 bool>
529 invokeMethod(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
530 Func &&function, Args &&...args)
531 {
532 using R = typename QtPrivate::Callable<Func, Args...>::ReturnType;
533 QTemplatedMetaMethodReturnArgument<R> r{ QtPrivate::qMetaTypeInterfaceForType<R>(), nullptr,
534 nullptr };
535 return invokeMethod(object, std::forward<Func>(function), Qt::AutoConnection, r,
536 std::forward<Args>(args)...);
537 }
538
539#endif
540
541#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
542 QObject *newInstance(QGenericArgument val0,
543 QGenericArgument val1 = QGenericArgument(),
544 QGenericArgument val2 = QGenericArgument(),
545 QGenericArgument val3 = QGenericArgument(),
546 QGenericArgument val4 = QGenericArgument(),
547 QGenericArgument val5 = QGenericArgument(),
548 QGenericArgument val6 = QGenericArgument(),
549 QGenericArgument val7 = QGenericArgument(),
550 QGenericArgument val8 = QGenericArgument(),
551 QGenericArgument val9 = QGenericArgument()) const;
552#endif
553
554 template <typename... Args>
555#ifdef Q_QDOC
556 QObject *
557#else
558 QtPrivate::Invoke::IfNotOldStyleArgs<QObject *, Args...>
559#endif
560 newInstance(Args &&... arguments) const
561 {
562 auto h = QtPrivate::invokeMethodHelper(QMetaMethodReturnArgument{}, std::forward<Args>(arguments)...);
563 return newInstanceImpl(this, h.parameterCount(), h.parameters.data(),
564 h.typeNames.data(), h.metaTypes.data());
565 }
566
567 enum Call {
568 InvokeMetaMethod,
569 ReadProperty,
570 WriteProperty,
571 ResetProperty,
572 CreateInstance,
573 IndexOfMethod,
574 RegisterPropertyMetaType,
575 RegisterMethodArgumentMetaType,
576 BindableProperty,
577 CustomCall,
578 ConstructInPlace,
579 };
580
581 int static_metacall(Call, int, void **) const;
582 static int metacall(QObject *, Call, int, void **);
583
584 template <const QMetaObject &MO> static constexpr const QMetaObject *staticMetaObject()
585 {
586 return &MO;
587 }
588
589 struct SuperData {
590 using Getter = const QMetaObject *(*)();
591 const QMetaObject *direct;
592 SuperData() = default;
593 constexpr SuperData(std::nullptr_t) : direct(nullptr) {}
594 constexpr SuperData(const QMetaObject *mo) : direct(mo) {}
595
596 constexpr const QMetaObject *operator->() const { return operator const QMetaObject *(); }
597
598#ifdef QT_NO_DATA_RELOCATION
599 Getter indirect = nullptr;
600 constexpr SuperData(Getter g) : direct(nullptr), indirect(g) {}
601 constexpr operator const QMetaObject *() const
602 { return indirect ? indirect() : direct; }
603 template <const QMetaObject &MO> static constexpr SuperData link()
604 { return SuperData(QMetaObject::staticMetaObject<MO>); }
605#else
606 constexpr SuperData(Getter g) : direct(g()) {}
607 constexpr operator const QMetaObject *() const
608 { return direct; }
609 template <const QMetaObject &MO> static constexpr SuperData link()
610 { return SuperData(QMetaObject::staticMetaObject<MO>()); }
611#endif
612 };
613
614 struct Data { // private data
615 SuperData superdata;
616 const uint *stringdata;
617 const uint *data;
618 typedef void (*StaticMetacallFunction)(QObject *, QMetaObject::Call, int, void **);
619 StaticMetacallFunction static_metacall;
620 const SuperData *relatedMetaObjects;
621 const QtPrivate::QMetaTypeInterface *const *metaTypes;
622 void *extradata; //reserved for future use
623 } d;
624
625private:
626 // Just need to have this here with a separate name so the other inline
627 // functions can call this without any ambiguity
628 template <typename Func, typename... Args>
629 static bool
630 invokeMethodCallableHelper(typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *object,
631 Func &&function, Qt::ConnectionType type, const QMetaMethodReturnArgument &ret,
632 Args &&...args)
633 {
634 using Callable = QtPrivate::Callable<Func, Args...>;
635 using ExpectedArguments = typename Callable::Arguments;
636 static_assert(sizeof...(Args) <= ExpectedArguments::size, "Too many arguments");
637 using ActualArguments = QtPrivate::List<Args...>;
638 static_assert(QtPrivate::CheckCompatibleArguments<ActualArguments,
639 ExpectedArguments>::value,
640 "Incompatible arguments");
641
642 auto h = QtPrivate::invokeMethodHelper(ret, std::forward<Args>(args)...);
643
644 // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks)
645 auto callable = new QtPrivate::QCallableObject<std::decay_t<Func>, ActualArguments,
646 typename Callable::ReturnType>(std::forward<Func>(function));
647 return invokeMethodImpl(object, callable, type, h.parameterCount(), h.parameters.data(),
648 h.typeNames.data(), h.metaTypes.data());
649 // NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
650 }
651
652 static bool invokeMethodImpl(QObject *object, const char *member, Qt::ConnectionType type,
653 qsizetype parameterCount, const void *const *parameters, const char *const *names,
654 const QtPrivate::QMetaTypeInterface * const *metaTypes);
655 static bool invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *slotObj,
656 Qt::ConnectionType type, qsizetype parameterCount,
657 const void *const *params, const char *const *names,
658 const QtPrivate::QMetaTypeInterface *const *metaTypes);
659#if QT_CORE_REMOVED_SINCE(6, 7)
660 static bool invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *slot, Qt::ConnectionType type, void *ret);
661#endif
662 static QObject *newInstanceImpl(const QMetaObject *mobj, qsizetype parameterCount,
663 const void **parameters, const char **typeNames,
664 const QtPrivate::QMetaTypeInterface **metaTypes);
665
666 static QMetaObject::Connection connectImpl(const QObject *sender, const QMetaMethod& signal,
667 const QObject *receiver, void **slotPtr,
668 QtPrivate::QSlotObjectBase *slot, Qt::ConnectionType type);
669
670 friend class QTimer;
671 friend class QChronoTimer;
672};
673
674class Q_CORE_EXPORT QMetaObject::Connection {
675 void *d_ptr; //QObjectPrivate::Connection*
676 explicit Connection(void *data) : d_ptr(data) { }
677 friend class QObject;
678 friend class QObjectPrivate;
679 friend struct QMetaObject;
680 bool isConnected_helper() const;
681public:
682 ~Connection();
683 Connection();
684 Connection(const Connection &other);
685 Connection &operator=(const Connection &other);
686#ifdef Q_QDOC
687 operator bool() const;
688#else
689 // still using the restricted bool trick here, in order to support
690 // code using copy-init (e.g. `bool ok = connect(...)`)
691 typedef void *Connection::*RestrictedBool;
692 operator RestrictedBool() const { return d_ptr && isConnected_helper() ? &Connection::d_ptr : nullptr; }
693#endif
694
695 Connection(Connection &&other) noexcept : d_ptr(std::exchange(other.d_ptr, nullptr)) {}
696 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(Connection)
697 void swap(Connection &other) noexcept { qt_ptr_swap(d_ptr, other.d_ptr); }
698};
699
700template <typename Func>
701QMetaObject::Connection
702 QMetaObject::connect(const QObject *sender, const QMetaMethod &signal,
703 const typename QtPrivate::ContextTypeForFunctor<Func>::ContextType *context, Func &&slot,
704 Qt::ConnectionType type)
705{
706 using Slot = std::decay_t<Func>;
707 using FunctionSlotType = QtPrivate::FunctionPointer<Slot>;
708 void **pSlot = nullptr;
709 QtPrivate::QSlotObjectBase *slotObject;
710 if constexpr (FunctionSlotType::ArgumentCount != -1) {
711 slotObject = new QtPrivate::QCallableObject<Slot, typename FunctionSlotType::Arguments, typename FunctionSlotType::ReturnType>(std::forward<Func>(slot));
712 if constexpr (FunctionSlotType::IsPointerToMemberFunction) {
713 pSlot = const_cast<void **>(reinterpret_cast<void *const *>(&slot));
714 } else {
715 Q_ASSERT_X((type & Qt::UniqueConnection) == 0, "",
716 "QObject::connect: Unique connection requires the slot to be a pointer to "
717 "a member function of a QObject subclass.");
718 }
719 } else {
720 using FunctorSlotType = QtPrivate::FunctionPointer<decltype(&Slot::operator())>;
721 slotObject = new QtPrivate::QCallableObject<Slot, typename FunctorSlotType::Arguments, typename FunctorSlotType::ReturnType>(std::forward<Func>(slot));
722 }
723 return QMetaObject::connectImpl(sender, signal, context, pSlot, slotObject, type);
724}
725
726inline void swap(QMetaObject::Connection &lhs, QMetaObject::Connection &rhs) noexcept
727{
728 lhs.swap(rhs);
729}
730
731inline const QMetaObject *QMetaObject::superClass() const
732{ return d.superdata; }
733
734namespace QtPrivate {
735 // Trait that tells if a QObject has a Q_OBJECT macro
736 template <typename Object> struct HasQ_OBJECT_Macro {
737 template <typename T>
738 static char test(int (T::*)(QMetaObject::Call, int, void **));
739 static int test(int (Object::*)(QMetaObject::Call, int, void **));
740 enum { Value = sizeof(test(&Object::qt_metacall)) == sizeof(int) };
741 };
742
743 template <class TgtType, class SrcType>
744 inline TgtType qobject_cast_helper(SrcType *object)
745 {
746 using ObjType = std::remove_cv_t<std::remove_pointer_t<TgtType>> ;
747 static_assert(std::is_pointer_v<TgtType>,
748 "qobject_cast requires to cast towards a pointer type");
749 static_assert(HasQ_OBJECT_Macro<ObjType>::Value,
750 "qobject_cast requires the type to have a Q_OBJECT macro");
751
752 if constexpr (std::is_final_v<ObjType>) {
753 if (object && object->metaObject() == &ObjType::staticMetaObject)
754 return static_cast<TgtType>(object);
755 return nullptr;
756 } else {
757 return static_cast<TgtType>(ObjType::staticMetaObject.cast(object));
758 }
759 }
760}
761
762QT_END_NAMESPACE
763
764#endif // QOBJECTDEFS_H
\inmodule QtCore
Definition qrandom.h:212
void discard(unsigned long long z)
Definition qrandom.h:240
result_type operator()()
Generates a 64-bit random quantity and returns it.
Definition qrandom.h:220
static constexpr result_type min()
Definition qrandom.h:247
quint64 result_type
A typedef to the type that operator() returns.
Definition qrandom.h:219
QRandomGenerator64(std::seed_seq &sseq) noexcept
Definition qrandom.h:232
QRandomGenerator64(const QRandomGenerator &other)
Definition qrandom.h:238
quint64 generate()
Generates one 64-bit random value and returns it.
Definition qrandom.h:217
QRandomGenerator64(quint32 seedValue=1)
Definition qrandom.h:223
QRandomGenerator64(const quint32 *begin, const quint32 *end)
Definition qrandom.h:235
QRandomGenerator64(const quint32 *seedBuffer, qsizetype len)
Definition qrandom.h:229
static constexpr result_type max()
Definition qrandom.h:248
QRandomGenerator64(const quint32(&seedBuffer)[N])
Definition qrandom.h:226
Combined button and popup list for selecting options.
QTemplatedMetaMethodReturnArgument< T > returnArgument(const char *name, T &t)
const void * dataHelper(const char *)=delete
const char * typenameHelper(QMetaMethodArgument a)
const QMetaTypeInterface * metaTypeHelper(const T &)
const QMetaTypeInterface * metaTypeHelper(const char16_t *)=delete
const QMetaTypeInterface * metaTypeHelper(QMetaMethodArgument a)
const QMetaTypeInterface * metaTypeHelper(const char *)=delete
const char * typenameHelper(const T &)
const void * dataHelper(const char16_t *)=delete
const void * dataHelper(QMetaMethodArgument a)
QMetaMethodArgument argument(const char *name, const T &t)
const void * dataHelper(const T &t)
const char * typenameHelper(const char16_t *)=delete
const char * typenameHelper(const char *)=delete
auto invokeMethodHelper(QMetaMethodReturnArgument r, const Args &... arguments)
TgtType qobject_cast_helper(SrcType *object)
constexpr const QMetaTypeInterface * qMetaTypeInterfaceForType()
Definition qmetatype.h:2656
#define assert
QMutex QBasicMutex
Definition qmutex.h:360
#define QT_STRINGIFY_METHOD(a)
Definition qobjectdefs.h:45
#define QT_PREFIX_CODE(code, a)
Definition qobjectdefs.h:44
#define QT_STRINGIFY_SIGNAL(a)
Definition qobjectdefs.h:47
void swap(QMetaObject::Connection &lhs, QMetaObject::Connection &rhs) noexcept
#define QSIGNAL_CODE
Definition qobjectdefs.h:43
QTemplatedMetaMethodReturnArgument< T > qReturnArg(T &data)
void qReturnArg(const T &&)=delete
#define QT_STRINGIFY_SLOT(a)
Definition qobjectdefs.h:46
#define QLOCATION
Definition qobjectdefs.h:49
Q_CORE_EXPORT const char * qFlagLocation(const char *method)
Definition qobject.cpp:2623
#define QSLOT_CODE
Definition qobjectdefs.h:42
#define QMETHOD_CODE
Definition qobjectdefs.h:41
static qsizetype callFillBuffer(FillBufferType f, T *v)
Definition qrandom.cpp:1265
static Q_NEVER_INLINE void fallback_fill(quint32 *ptr, qsizetype left) noexcept
Definition qrandom.cpp:210
static void fallback_update_seed(unsigned value)
Definition qrandom.cpp:198
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
Definition qrandom.cpp:1218
#define Q_ASSERT(cond)
Definition qrandom.cpp:48
QRandomGenerator::InitialRandomData qt_initial_random_value() noexcept
Definition qrandom.cpp:1286
RNGType
Definition qrandom_p.h:34
@ MersenneTwister
Definition qrandom_p.h:36
@ SystemRNG
Definition qrandom_p.h:35
QRandomGeneratorControl
Definition qrandom_p.h:25
@ UseSystemRNG
Definition qrandom_p.h:26
@ SkipSystemRNG
Definition qrandom_p.h:27
@ SetRandomData
Definition qrandom_p.h:28
@ RandomDataMask
Definition qrandom_p.h:31
const char * name
const QtPrivate::QMetaTypeInterface * metaType
const void * data
const QtPrivate::QMetaTypeInterface * metaType
\inmodule QtCore
static QRandomGenerator64 * system()
Definition qrandom.cpp:350
static void securelySeed(QRandomGenerator *rng)
Definition qrandom.cpp:367
static SystemAndGlobalGenerators * self()
Definition qrandom.cpp:343
static QRandomGenerator64 * globalNoInit()
Definition qrandom.cpp:359
uchar data[sizeof(QRandomGenerator64)]
Definition qrandom.cpp:327
void generate(quint32 *begin, quint32 *end) noexcept(FillBufferNoexcept)
Definition qrandom.cpp:283
static SystemGenerator & self()
Definition qrandom.cpp:394
void generate(T *begin, T *end)
Definition qrandom.cpp:153
static char test(int(T::*)(QMetaObject::Call, int, void **))
static int test(int(Object::*)(QMetaObject::Call, int, void **))