10#include <QtCore/qglobal.h>
11#include <QtCore/qatomic.h>
12#include <QtCore/qbytearray.h>
13#include <QtCore/qcompare.h>
14#include <QtCore/qdatastream.h>
15#include <QtCore/qflags.h>
16#include <QtCore/qfloat16.h>
17#include <QtCore/qhashfunctions.h>
18#include <QtCore/qiterable.h>
19#include <QtCore/qmetacontainer.h>
21#include <QtCore/qobjectdefs.h>
23#include <QtCore/qscopeguard.h>
24#include <QtCore/qttypetraits.h>
33#include <QtCore/qxptype_traits.h>
36#error qmetatype.h must be included before any header file that defines Bool
42enum class QCborSimpleType : quint8;
51#define QT_FOR_EACH_STATIC_PRIMITIVE_NON_VOID_TYPE(F)
55 F(LongLong, 4
, qlonglong)
56 F(ULongLong, 5
, qulonglong)
61 F(Char16, 56
, char16_t)
62 F(Char32, 57
, char32_t)
67 F(SChar, 40
, signed char)
68 F(Nullptr, 51
, std::nullptr_t)
69 F(QCborSimpleType, 52
, QCborSimpleType)
71#define QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(F)
75#define QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(F)
76 F(VoidStar, 31
, void*)
78#if QT_CONFIG(easingcurve)
79#define QT_FOR_EACH_STATIC_EASINGCURVE(F)
80 F(QEasingCurve, 29
, QEasingCurve)
82#define QT_FOR_EACH_STATIC_EASINGCURVE(F)
85#if QT_CONFIG(itemmodel)
86#define QT_FOR_EACH_STATIC_ITEMMODEL_CLASS(F)
87 F(QModelIndex, 42
, QModelIndex)
88 F(QPersistentModelIndex, 50
, QPersistentModelIndex)
90#define QT_FOR_EACH_STATIC_ITEMMODEL_CLASS(F)
93#if QT_CONFIG(regularexpression)
94# define QT_FOR_EACH_STATIC_REGULAR_EXPRESSION(F)
95 F(QRegularExpression, 44
, QRegularExpression)
97# define QT_FOR_EACH_STATIC_REGULAR_EXPRESSION(F)
100# define QT_FOR_EACH_STATIC_QVARIANT(F)
101 F(QVariant, 41
, QVariant)
103# define QT_FOR_EACH_STATIC_QVARIANT(F)
106#define QT_FOR_EACH_STATIC_CORE_CLASS(F)
108 F(QString, 10
, QString)
109 F(QByteArray, 12
, QByteArray)
110 F(QBitArray, 13
, QBitArray)
113 F(QDateTime, 16
, QDateTime)
115 F(QLocale, 18
, QLocale)
117 F(QRectF, 20
, QRectF)
119 F(QSizeF, 22
, QSizeF)
121 F(QLineF, 24
, QLineF)
122 F(QPoint, 25
, QPoint)
123 F(QPointF, 26
, QPointF)
128 F(QJsonValue, 45
, QJsonValue)
129 F(QJsonObject, 46
, QJsonObject)
130 F(QJsonArray, 47
, QJsonArray)
131 F(QJsonDocument, 48
, QJsonDocument)
132 F(QCborValue, 53
, QCborValue)
133 F(QCborArray, 54
, QCborArray)
134 F(QCborMap, 55
, QCborMap)
135 F(Float16, 63
, qfloat16)
138#define QT_FOR_EACH_STATIC_CORE_POINTER(F)
139 F(QObjectStar, 39
, QObject*)
142# define QT_FOR_EACH_STATIC_CORE_QVARIANT_TEMPLATE(F)
143 F(QVariantMap, 8
, QVariantMap)
144 F(QVariantList, 9
, QVariantList)
145 F(QVariantHash, 28
, QVariantHash)
146 F(QVariantPair, 58
, QVariantPair)
149# define QT_FOR_EACH_STATIC_CORE_QVARIANT_TEMPLATE(F)
152#define QT_FOR_EACH_STATIC_CORE_TEMPLATE(F)
154 F(QByteArrayList, 49
, QByteArrayList)
155 F(QStringList, 11
, QStringList)
157#if QT_CONFIG(shortcut)
158#define QT_FOR_EACH_STATIC_KEYSEQUENCE_CLASS(F)
159 F(QKeySequence, 0x100b
, QKeySequence)
161#define QT_FOR_EACH_STATIC_KEYSEQUENCE_CLASS(F)
164#define QT_FOR_EACH_STATIC_GUI_CLASS(F)
165 F(QFont, 0x1000
, QFont)
166 F(QPixmap, 0x1001
, QPixmap)
167 F(QBrush, 0x1002
, QBrush)
168 F(QColor, 0x1003
, QColor)
169 F(QPalette, 0x1004
, QPalette)
170 F(QIcon, 0x1005
, QIcon)
171 F(QImage, 0x1006
, QImage)
172 F(QPolygon, 0x1007
, QPolygon)
173 F(QRegion, 0x1008
, QRegion)
174 F(QBitmap, 0x1009
, QBitmap)
175 F(QCursor, 0x100a
, QCursor)
177 F(QPen, 0x100c
, QPen)
178 F(QTextLength, 0x100d
, QTextLength)
179 F(QTextFormat, 0x100e
, QTextFormat)
180 F(QTransform, 0x1010
, QTransform)
181 F(QMatrix4x4, 0x1011
, QMatrix4x4)
182 F(QVector2D, 0x1012
, QVector2D)
183 F(QVector3D, 0x1013
, QVector3D)
184 F(QVector4D, 0x1014
, QVector4D)
185 F(QQuaternion, 0x1015
, QQuaternion)
186 F(QPolygonF, 0x1016
, QPolygonF)
187 F(QColorSpace, 0x1017
, QColorSpace)
190#define QT_FOR_EACH_STATIC_WIDGETS_CLASS(F)
191 F(QSizePolicy, 0x2000
, QSizePolicy)
194#define QT_FOR_EACH_STATIC_ALIAS_TYPE(F)
195 F(ULong, -1
, ulong, "unsigned long")
196 F(UInt, -1
, uint, "unsigned int")
197 F(UShort, -1
, ushort, "unsigned short")
198 F(UChar, -1
, uchar, "unsigned char")
199 F(LongLong, -1
, qlonglong, "long long")
200 F(ULongLong, -1
, qulonglong, "unsigned long long")
201 F(SChar, -1
, signed char, "qint8")
202 F(UChar, -1
, uchar, "quint8")
203 F(Short, -1
, short, "qint16")
204 F(UShort, -1
, ushort, "quint16")
205 F(Int, -1
, int, "qint32")
206 F(UInt, -1
, uint, "quint32")
207 F(LongLong, -1
, qlonglong, "qint64")
208 F(ULongLong, -1
, qulonglong, "quint64")
209 F(QByteArrayList, -1
, QByteArrayList, "QList<QByteArray>")
210 F(QStringList, -1
, QStringList, "QList<QString>")
214#define QT_FOR_EACH_STATIC_VARIANT_ALIAS_TYPE(F)
215 F(QVariantList, -1
, QVariantList, "QList<QVariant>")
216 F(QVariantMap, -1
, QVariantMap, "QMap<QString,QVariant>")
217 F(QVariantHash, -1
, QVariantHash, "QHash<QString,QVariant>")
218 F(QVariantPair, -1
, QVariantPair, "QPair<QVariant,QVariant>")
221#define QT_FOR_EACH_STATIC_VARIANT_ALIAS_TYPE(F)
224#define QT_FOR_EACH_STATIC_TYPE(F)
233#define QT_DEFINE_METATYPE_ID(TypeName, Id, Name)
236#define QT_FOR_EACH_AUTOMATIC_TEMPLATE_1ARG(F)
243#define QT_FOR_EACH_AUTOMATIC_TEMPLATE_2ARG(F)
247#define QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER(F)
264#if QT_VERSION >= QT_VERSION_CHECK(7
, 0
, 0
) || defined(QT_BOOTSTRAPPED) || !defined(Q_CC_MSVC)
268# define QMTI_MUTABLE mutable
318
319
320
321template<
typename From,
typename To>
327 template<
typename T,
bool>
329 template<
typename T,
bool>
331 template<
typename T,
bool>
333 template<
typename,
typename>
340 template<
typename T,
typename ODR_VIOLATION_PREVENTER>
346 using type =
decltype(check(
static_cast<T *>(
nullptr)));
350 template <
typename T,
typename ODR_VIOLATION_PREVENTER =
void>
370 "Meta Types must be fully defined");
371 static_assert(!
std::is_reference_v<T>,
372 "Meta Types cannot be non-const references or rvalue references.");
374 using Pointed = std::remove_pointer_t<T>;
375 static_assert(is_complete<Pointed,
void>::value,
376 "Pointer Meta Types must either point to fully-defined types "
377 "or be declared with Q_DECLARE_OPAQUE_POINTER(T *)");
391 FirstCoreType = Bool,
392 LastCoreType = Float16,
393 FirstGuiType = QFont,
394 LastGuiType = QColorSpace,
395 FirstWidgetsType = QSizePolicy,
396 LastWidgetsType = QSizePolicy,
397 HighestInternalId = LastWidgetsType,
399 QReal =
sizeof(qreal) ==
sizeof(
double) ? Double : Float,
407 UnknownType = 0, Bool = 1, Int = 2, UInt = 3, LongLong = 4, ULongLong = 5,
408 Double = 6, Long = 32, Short = 33, Char = 34, ULong = 35, UShort = 36,
409 UChar = 37, Float = 38,
411 QChar = 7, QString = 10, QStringList = 11, QByteArray = 12,
412 QBitArray = 13, QDate = 14, QTime = 15, QDateTime = 16, QUrl = 17,
413 QLocale = 18, QRect = 19, QRectF = 20, QSize = 21, QSizeF = 22,
414 QLine = 23, QLineF = 24, QPoint = 25, QPointF = 26,
415 QEasingCurve = 29, QUuid = 30, QVariant = 41, QModelIndex = 42,
416 QPersistentModelIndex = 50, QRegularExpression = 44,
417 QJsonValue = 45, QJsonObject = 46, QJsonArray = 47, QJsonDocument = 48,
418 QByteArrayList = 49, QObjectStar = 39, SChar = 40,
421 QVariantMap = 8, QVariantList = 9, QVariantHash = 28, QVariantPair = 58,
422 QCborSimpleType = 52, QCborValue = 53, QCborArray = 54, QCborMap = 55,
423 Char16 = 56, Char32 = 57,
424 Int128 = 59, UInt128 = 60, Float128 = 61, BFloat16 = 62, Float16 = 63,
427 QFont = 0x1000, QPixmap = 0x1001, QBrush = 0x1002, QColor = 0x1003, QPalette = 0x1004,
428 QIcon = 0x1005, QImage = 0x1006, QPolygon = 0x1007, QRegion = 0x1008, QBitmap = 0x1009,
429 QCursor = 0x100a, QKeySequence = 0x100b, QPen = 0x100c, QTextLength = 0x100d, QTextFormat = 0x100e,
430 QTransform = 0x1010, QMatrix4x4 = 0x1011, QVector2D = 0x1012,
431 QVector3D = 0x1013, QVector4D = 0x1014, QQuaternion = 0x1015, QPolygonF = 0x1016, QColorSpace = 0x1017,
434 QSizePolicy = 0x2000,
442 NeedsConstruction = 0x1,
443 NeedsDestruction = 0x2,
444 RelocatableType = 0x4,
445#if QT_DEPRECATED_SINCE(6
, 0
)
446 MovableType Q_DECL_ENUMERATOR_DEPRECATED_X(
"Use RelocatableType instead.") = RelocatableType,
448 PointerToQObject = 0x8,
449 IsEnumeration = 0x10,
450 SharedPointerToQObject = 0x20,
451 WeakPointerToQObject = 0x40,
452 TrackingPointerToQObject = 0x80,
453 IsUnsignedEnumeration = 0x100,
455 PointerToGadget = 0x400,
460 NeedsCopyConstruction = 0x4000,
461 NeedsMoveConstruction = 0x8000,
463 Q_DECLARE_FLAGS(TypeFlags, TypeFlag)
465 static void registerNormalizedTypedef(
const QT_PREPEND_NAMESPACE(QByteArray) &normalizedTypeName, QMetaType type);
467#if QT_DEPRECATED_SINCE(6
, 0
)
468 QT_DEPRECATED_VERSION_6_0
469 static int type(
const char *typeName)
470 {
return QMetaType::fromName(typeName).rawId(); }
471 QT_DEPRECATED_VERSION_6_0
472 static int type(
const QT_PREPEND_NAMESPACE(QByteArray) &typeName)
473 {
return QMetaType::fromName(typeName).rawId(); }
474 QT_DEPRECATED_VERSION_6_0
475 static const char *typeName(
int type)
476 {
return QMetaType(type).name(); }
477 QT_DEPRECATED_VERSION_6_0
478 static int sizeOf(
int type)
479 {
return int(QMetaType(type).sizeOf()); }
480 QT_DEPRECATED_VERSION_6_0
481 static TypeFlags typeFlags(
int type)
482 {
return QMetaType(type).flags(); }
483 QT_DEPRECATED_VERSION_6_0
484 static const QMetaObject *metaObjectForType(
int type)
485 {
return QMetaType(type).metaObject(); }
486 QT_DEPRECATED_VERSION_6_0
487 static void *create(
int type,
const void *copy =
nullptr)
488 {
return QMetaType(type).create(copy); }
489 QT_DEPRECATED_VERSION_6_0
490 static void destroy(
int type,
void *data)
491 {
return QMetaType(type).destroy(data); }
492 QT_DEPRECATED_VERSION_6_0
493 static void *construct(
int type,
void *where,
const void *copy)
494 {
return QMetaType(type).construct(where, copy); }
495 QT_DEPRECATED_VERSION_6_0
496 static void destruct(
int type,
void *where)
497 {
return QMetaType(type).destruct(where); }
499 static bool isRegistered(
int type);
501 explicit QMetaType(
int type);
502 explicit constexpr QMetaType(
const QtPrivate::QMetaTypeInterface *d) : d_ptr(d) {}
503 constexpr QMetaType() =
default;
505#if QT_CORE_REMOVED_SINCE(6
, 9
)
506 bool isValid()
const;
507 bool isRegistered()
const;
509 constexpr bool isValid(QT6_DECL_NEW_OVERLOAD)
const noexcept;
510 inline bool isRegistered(QT6_DECL_NEW_OVERLOAD)
const noexcept;
511 void registerType()
const
516#if QT_CORE_REMOVED_SINCE(6
, 1
) || defined(Q_QDOC)
521 int id(
int = 0)
const
523 return registerHelper();
528 Q_PRE(!isValid(QT6_CALL_NEW_OVERLOAD) || isRegistered(QT6_CALL_NEW_OVERLOAD));
529 return d_ptr ? d_ptr->typeId.loadRelaxed() : 0;
532 template <
typename Type>
constexpr bool isSameType()
const
534 using T =
typename QtPrivate::MetatypeDecay<Type>::type;
535 QMetaType other = fromType<T>();
536 if (q20::is_constant_evaluated()) {
539 return d_ptr == other.iface();
541 using IsBuiltIn = std::bool_constant<QMetaTypeId2<T>::IsBuiltIn>;
542 return isSameTypeHelper<T>(other.iface(), IsBuiltIn{});
546 constexpr qsizetype sizeOf()
const;
547 constexpr qsizetype alignOf()
const;
548 constexpr TypeFlags flags()
const;
549 constexpr const QMetaObject *metaObject()
const;
550 constexpr const char *name()
const;
552 void *create(
const void *copy =
nullptr)
const;
553 void destroy(
void *data)
const;
554 void *construct(
void *where,
const void *copy =
nullptr)
const;
555 void destruct(
void *data)
const;
556 QPartialOrdering compare(
const void *lhs,
const void *rhs)
const;
557 bool equals(
const void *lhs,
const void *rhs)
const;
559 bool isDefaultConstructible()
const noexcept {
return d_ptr && isDefaultConstructible(d_ptr); }
560 bool isCopyConstructible()
const noexcept {
return d_ptr && isCopyConstructible(d_ptr); }
561 bool isMoveConstructible()
const noexcept {
return d_ptr && isMoveConstructible(d_ptr); }
562 bool isDestructible()
const noexcept {
return d_ptr && isDestructible(d_ptr); }
563 bool isEqualityComparable()
const;
564 bool isOrdered()
const;
566#ifndef QT_NO_DATASTREAM
567 bool save(QDataStream &stream,
const void *data)
const;
568 bool load(QDataStream &stream,
void *data)
const;
569 bool hasRegisteredDataStreamOperators()
const;
571#if QT_DEPRECATED_SINCE(6
, 0
)
572 QT_DEPRECATED_VERSION_6_0
573 static bool save(QDataStream &stream,
int type,
const void *data)
574 {
return QMetaType(type).save(stream, data); }
575 QT_DEPRECATED_VERSION_6_0
576 static bool load(QDataStream &stream,
int type,
void *data)
577 {
return QMetaType(type).load(stream, data); }
581 QMetaType underlyingType()
const;
584 constexpr static QMetaType fromType();
585 static QMetaType fromName(QByteArrayView name);
587 friend bool comparesEqual(
const QMetaType &lhs,
588 const QMetaType &rhs)
590 if (lhs.d_ptr == rhs.d_ptr)
592 if (!lhs.d_ptr || !rhs.d_ptr)
595 const int aId = lhs.id();
596 const int bId = rhs.id();
599 Q_DECLARE_EQUALITY_COMPARABLE_NON_NOEXCEPT(QMetaType)
600#ifndef QT_NO_DEBUG_STREAM
602 friend Q_CORE_EXPORT QDebug operator<<(QDebug d, QMetaType m);
604 bool debugStream(QDebug& dbg,
const void *rhs);
605 bool hasRegisteredDebugStreamOperator()
const;
607#if QT_DEPRECATED_SINCE(6
, 0
)
608 QT_DEPRECATED_VERSION_6_0
609 static bool debugStream(QDebug& dbg,
const void *rhs,
int typeId)
610 {
return QMetaType(typeId).debugStream(dbg, rhs); }
612 QT_DEPRECATED_VERSION_6_0
613 static bool hasRegisteredDebugStreamOperator()
614 {
return QMetaType::fromType<T>().hasRegisteredDebugStreamOperator(); }
615 QT_DEPRECATED_VERSION_6_0
616 static bool hasRegisteredDebugStreamOperator(
int typeId)
617 {
return QMetaType(typeId).hasRegisteredDebugStreamOperator(); }
623 using ConverterFunction = std::function<
bool(
const void *src,
void *target)>;
626 using MutableViewFunction = std::function<
bool(
void *src,
void *target)>;
629 template<
typename From,
typename To>
630 static bool registerConverter()
632 return registerConverter<From, To>(QtPrivate::convertImplicit<From, To>);
636 template<
typename From,
typename To>
637 static bool registerConverter(To(From::*function)()
const)
639 static_assert((!QMetaTypeId2<To>::IsBuiltIn || !QMetaTypeId2<From>::IsBuiltIn),
640 "QMetaType::registerConverter: At least one of the types must be a custom type.");
642 const QMetaType fromType = QMetaType::fromType<From>();
643 const QMetaType toType = QMetaType::fromType<To>();
644 auto converter = [function](
const void *from,
void *to) ->
bool {
645 const From *f =
static_cast<
const From *>(from);
646 To *t =
static_cast<To *>(to);
647 *t = (f->*function)();
650 return registerConverterImpl<From, To>(converter, fromType, toType);
654 template<
typename From,
typename To>
655 static bool registerMutableView(To(From::*function)())
657 static_assert((!QMetaTypeId2<To>::IsBuiltIn || !QMetaTypeId2<From>::IsBuiltIn),
658 "QMetaType::registerMutableView: At least one of the types must be a custom type.");
660 const QMetaType fromType = QMetaType::fromType<From>();
661 const QMetaType toType = QMetaType::fromType<To>();
662 auto view = [function](
void *from,
void *to) ->
bool {
663 From *f =
static_cast<From *>(from);
664 To *t =
static_cast<To *>(to);
665 *t = (f->*function)();
668 return registerMutableViewImpl<From, To>(view, fromType, toType);
672 template<
typename From,
typename To>
673 static bool registerConverter(To(From::*function)(
bool*)
const)
675 static_assert((!QMetaTypeId2<To>::IsBuiltIn || !QMetaTypeId2<From>::IsBuiltIn),
676 "QMetaType::registerConverter: At least one of the types must be a custom type.");
678 const QMetaType fromType = QMetaType::fromType<From>();
679 const QMetaType toType = QMetaType::fromType<To>();
680 auto converter = [function](
const void *from,
void *to) ->
bool {
681 const From *f =
static_cast<
const From *>(from);
682 To *t =
static_cast<To *>(to);
684 *t = (f->*function)(&result);
689 return registerConverterImpl<From, To>(converter, fromType, toType);
693 template<
typename From,
typename To,
typename UnaryFunction>
694 static bool registerConverter(UnaryFunction function)
696 static_assert((!QMetaTypeId2<To>::IsBuiltIn || !QMetaTypeId2<From>::IsBuiltIn),
697 "QMetaType::registerConverter: At least one of the types must be a custom type.");
699 const QMetaType fromType = QMetaType::fromType<From>();
700 const QMetaType toType = QMetaType::fromType<To>();
701 auto converter = [function = std::move(function)](
const void *from,
void *to) ->
bool {
702 const From *f =
static_cast<
const From *>(from);
703 To *t =
static_cast<To *>(to);
704 decltype(
auto) r = function(*f);
705 if constexpr (std::is_same_v<q20::remove_cvref_t<
decltype(r)>, std::optional<To>>) {
708 *t = *std::forward<
decltype(r)>(r);
710 *t = std::forward<
decltype(r)>(r);
714 return registerConverterImpl<From, To>(std::move(converter), fromType, toType);
718 template<
typename From,
typename To,
typename UnaryFunction>
719 static bool registerMutableView(UnaryFunction function)
721 static_assert((!QMetaTypeId2<To>::IsBuiltIn || !QMetaTypeId2<From>::IsBuiltIn),
722 "QMetaType::registerMutableView: At least one of the types must be a custom type.");
724 const QMetaType fromType = QMetaType::fromType<From>();
725 const QMetaType toType = QMetaType::fromType<To>();
726 auto view = [function = std::move(function)](
void *from,
void *to) ->
bool {
727 From *f =
static_cast<From *>(from);
728 To *t =
static_cast<To *>(to);
732 return registerMutableViewImpl<From, To>(std::move(view), fromType, toType);
736 template<
typename From,
typename To>
737 static bool registerConverterImpl(ConverterFunction converter, QMetaType fromType, QMetaType toType)
739 if (registerConverterFunction(std::move(converter), fromType, toType)) {
740 static const auto unregister = qScopeGuard([=] {
741 unregisterConverterFunction(fromType, toType);
749 template<
typename From,
typename To>
750 static bool registerMutableViewImpl(MutableViewFunction view, QMetaType fromType, QMetaType toType)
752 if (registerMutableViewFunction(std::move(view), fromType, toType)) {
753 static const auto unregister = qScopeGuard([=] {
754 unregisterMutableViewFunction(fromType, toType);
763 static bool convert(QMetaType fromType,
const void *from, QMetaType toType,
void *to);
764 static bool canConvert(QMetaType fromType, QMetaType toType);
766 static bool view(QMetaType fromType,
void *from, QMetaType toType,
void *to);
767 static bool canView(QMetaType fromType, QMetaType toType);
768#if QT_DEPRECATED_SINCE(6
, 0
)
769 QT_DEPRECATED_VERSION_6_0
770 static bool convert(
const void *from,
int fromTypeId,
void *to,
int toTypeId)
771 {
return convert(QMetaType(fromTypeId), from, QMetaType(toTypeId), to); }
772 QT_DEPRECATED_VERSION_6_0
773 static bool compare(
const void *lhs,
const void *rhs,
int typeId,
int *result)
776 auto c = t.compare(lhs, rhs);
777 if (c == QPartialOrdering::Unordered) {
780 }
else if (c == QPartialOrdering::Less) {
783 }
else if (c == QPartialOrdering::Equivalent) {
791 QT_DEPRECATED_VERSION_6_0
792 static bool equals(
const void *lhs,
const void *rhs,
int typeId,
int *result)
795 if (!t.isEqualityComparable())
797 *result = t.equals(lhs, rhs) ? 0 : -1;
802 template<
typename From,
typename To>
803 static bool hasRegisteredConverterFunction()
805 return hasRegisteredConverterFunction(
806 QMetaType::fromType<From>(), QMetaType::fromType<To>());
809 static bool hasRegisteredConverterFunction(QMetaType fromType, QMetaType toType);
811 template<
typename From,
typename To>
812 static bool hasRegisteredMutableViewFunction()
814 return hasRegisteredMutableViewFunction(
815 QMetaType::fromType<From>(), QMetaType::fromType<To>());
818 static bool hasRegisteredMutableViewFunction(QMetaType fromType, QMetaType toType);
821 template<
typename,
bool>
friend struct QtPrivate::SequentialValueTypeIsMetaType;
822 template<
typename,
bool>
friend struct QtPrivate::AssociativeValueTypeIsMetaType;
823 template<
typename,
bool>
friend struct QtPrivate::IsMetaTypePair;
824 template<
typename,
typename>
friend struct QtPrivate::MetaTypeSmartPointerHelper;
826 static bool registerConverterFunction(
const ConverterFunction &f, QMetaType from, QMetaType to);
827 static void unregisterConverterFunction(QMetaType from, QMetaType to);
829 static bool registerMutableViewFunction(
const MutableViewFunction &f, QMetaType from, QMetaType to);
830 static void unregisterMutableViewFunction(QMetaType from, QMetaType to);
832 static void unregisterMetaType(QMetaType type);
834#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
835 constexpr const QtPrivate::QMetaTypeInterface *iface() {
return d_ptr; }
837 constexpr const QtPrivate::QMetaTypeInterface *iface()
const {
return d_ptr; }
840 Q_DECL_PURE_FUNCTION
static bool isDefaultConstructible(
const QtPrivate::QMetaTypeInterface *)
noexcept;
841 Q_DECL_PURE_FUNCTION
static bool isCopyConstructible(
const QtPrivate::QMetaTypeInterface *)
noexcept;
842 Q_DECL_PURE_FUNCTION
static bool isMoveConstructible(
const QtPrivate::QMetaTypeInterface *)
noexcept;
843 Q_DECL_PURE_FUNCTION
static bool isDestructible(
const QtPrivate::QMetaTypeInterface *)
noexcept;
845 template <
typename T>
bool
846 isSameTypeHelper(
const QtPrivate::QMetaTypeInterface *iface, std::true_type)
const noexcept;
847 template <
typename T>
bool
848 isSameTypeHelper(
const QtPrivate::QMetaTypeInterface *iface, std::false_type)
const;
849#if QT_CORE_REMOVED_SINCE(6
, 5
)
850 int idHelper()
const;
852 static int registerHelper(
const QtPrivate::QMetaTypeInterface *iface);
853 int registerHelper()
const
856 if (
int id = d_ptr->typeId.loadRelaxed(); Q_LIKELY(id))
858 return registerHelper(d_ptr);
863 friend int qRegisterMetaType(QMetaType meta);
865 friend class QVariant;
866 const QtPrivate::QMetaTypeInterface *d_ptr =
nullptr;
869#undef QT_DEFINE_METATYPE_ID
871Q_DECLARE_OPERATORS_FOR_FLAGS(QMetaType::TypeFlags)
873#define QT_METATYPE_PRIVATE_DECLARE_TYPEINFO(C, F)
875 Q_DECLARE_TYPEINFO(QtMetaTypePrivate:: C, (F));
876 namespace QtMetaTypePrivate {
888 typedef void (*
getFunc)(
const void *
const *p,
void *);
895 { *
static_cast<
typename T::first_type *>(dataPtr) =
static_cast<
const T*>(*pair)->first; }
898 { *
static_cast<
typename T::second_type *>(dataPtr) =
static_cast<
const T*>(*pair)->second; }
922template<
typename From>
925template<
typename T,
typename U>
938#define QT_FORWARD_DECLARE_SHARED_POINTER_TYPES_ITER(Name)
939 template <class T> class Name;
982 enum {
Value =
sizeof(checkType(
static_cast<T*>(
nullptr))) ==
sizeof(
yes_type) };
985 template<
typename T,
typename Enable =
void>
991 template <
typename X>
995 IsRealGadget =
sizeof(checkType(&T::qt_check_for_QGADGET_macro)) ==
sizeof(
void *),
1000 template <
typename T>
1003 template<
typename T,
typename Enable =
void>
1006 template<
typename T>
1010 template <
typename X>
1022 template<
typename T>
1033 template<
typename T,
typename Enable =
void>
1036 static constexpr const QMetaObject *
value() {
return nullptr; }
1040#ifndef QT_NO_QOBJECT
1041 template<
typename T>
1047 template<
typename T>
1058 template<
typename T>
1067 template<
typename T>
1075 template<
typename T>
1081 template<
typename T>
1086 template<
typename T>
1092 template<
typename T>
1097 template<
typename T>
1103 template<
typename T>
1109 template<
typename T>
1115 template<
typename T>
1135 template<
typename T,
bool =
QMetaTypeId2<
typename T::value_type>::Defined>
1149 template<
typename T>
1168 template<
typename T,
bool =
QMetaTypeId2<
typename T::key_type>::Defined>
1182 template<
typename T,
bool =
QMetaTypeId2<
typename T::mapped_type>::Defined>
1196 template<
typename T>
1201 template<
typename T,
bool =
QMetaTypeId2<
typename T::first_type>::Defined
1211 template<
typename T>
1217 template<
typename T>
1225 template<
typename T,
typename U>
1228 template<
typename T>
1231 template<
typename T,
typename =
void>
1237#if QT_CONFIG(future)
1238 template<
typename T>
1247template <
typename T,
int =
1257template <
typename T>
1262template <
typename T>
1270template <
typename T>
1273template <
typename T>
1282 template <
typename T,
bool Defined =
QMetaTypeId2<T>::Defined>
1293 template <
typename Result,
typename... Args>
1296 template<
typename T>
1301 template<
typename T>
1304 template<
typename T,
bool defined>
1310 template<
typename SmartPointer>
1315 return p.operator->();
1321 template <
typename T>
1324 template<
typename T>
1334template <
typename T>
1337#ifndef QT_NO_QOBJECT
1338 Q_ASSERT_X(normalizedTypeName == QMetaObject::normalizedType(normalizedTypeName.constData()),
1339 "qRegisterNormalizedMetaType",
1340 "qRegisterNormalizedMetaType was called with a not normalized type name, "
1341 "please call qRegisterMetaType instead.");
1344 const QMetaType metaType = QMetaType::fromType<T>();
1345 const int id = metaType.id();
1347 QtPrivate::SequentialContainerTransformationHelper<T>::registerConverter();
1348 QtPrivate::SequentialContainerTransformationHelper<T>::registerMutableView();
1349 QtPrivate::AssociativeContainerTransformationHelper<T>::registerConverter();
1350 QtPrivate::AssociativeContainerTransformationHelper<T>::registerMutableView();
1352 QtPrivate::MetaTypeSmartPointerHelper<T>::registerConverter();
1353#if QT_CONFIG(future)
1354 QtPrivate::MetaTypeQFutureHelper<T>::registerConverter();
1357 if (normalizedTypeName != metaType.name())
1358 QMetaType::registerNormalizedTypedef(normalizedTypeName, metaType);
1373template <
typename T>
1376 return qRegisterNormalizedMetaTypeImplementation<T>(normalizedTypeName);
1379#if defined(QT_BOOTSTRAPPED)
1380#define QT_DECL_METATYPE_EXTERN_TAGGED(TYPE, TAG, EXPORT)
1381#define QT_IMPL_METATYPE_EXTERN_TAGGED(TYPE, TAG)
1383#define QT_DECL_METATYPE_EXTERN_TAGGED(TYPE, TAG, EXPORT)
1385 EXPORT int qRegisterNormalizedMetaType_ ## TAG (const QByteArray &);
1386 template <> inline int qRegisterNormalizedMetaType< TYPE >(const QByteArray &name)
1387 { return qRegisterNormalizedMetaType_ ## TAG (name); }
1391#define QT_IMPL_METATYPE_EXTERN_TAGGED(TYPE, TAG)
1392 int qRegisterNormalizedMetaType_ ## TAG (const QByteArray &name)
1393 { return qRegisterNormalizedMetaTypeImplementation< TYPE >(name); }
1396#define QT_DECL_METATYPE_EXTERN(TYPE, EXPORT)
1398#define QT_IMPL_METATYPE_EXTERN(TYPE)
1401template <
typename T>
1405 QT_PREPEND_NAMESPACE(QByteArray) normalizedTypeName = typeName;
1407 QT_PREPEND_NAMESPACE(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName);
1409 return qRegisterNormalizedMetaType<T>(normalizedTypeName);
1412template <
typename T>
1421 return QMetaType::fromType<T>().id();
1425template <
typename T>
1428 int id = qMetaTypeId<T>();
1434 return meta.registerHelper();
1437#ifndef QT_NO_QOBJECT
1438template <
typename T>
1439struct QMetaTypeIdQObject<T*, QMetaType::PointerToGadget>
1445 static int qt_metatype_id()
1448 QMetaType::fromType<std::remove_cv_t<T>>().registerType();
1449 if constexpr (std::is_const_v<T>)
1450 QMetaType::fromType<T>().registerType();
1451 return QMetaType::fromType<T *>().id();
1455template <
typename T>
1456struct QMetaTypeIdQObject<T, QMetaType::IsEnumeration>
1462 static int qt_metatype_id()
1464 Q_CONSTINIT
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0);
1465 if (
const int id = metatype_id.loadAcquire())
1469 const char *eName = qt_getEnumName(T());
1470 const char *cName = qt_getEnumMetaObject(T())->className();
1471 QByteArray typeName;
1472 constexpr bool isConst = std::is_const_v<T>;
1473 typeName.reserve(strlen(cName) + 2 + strlen(eName) + (isConst ? strlen(
"const ") : 0));
1474 if constexpr (isConst)
1475 typeName.append(
"const ");
1476 typeName.append(cName).append(
"::").append(eName);
1477 const int newId = qRegisterNormalizedMetaType<T>(typeName);
1478 metatype_id.storeRelease(newId);
1484#define Q_DECLARE_OPAQUE_POINTER(POINTER)
1485 QT_BEGIN_NAMESPACE namespace QtPrivate {
1486 template <> struct IsPointerDeclaredOpaque<POINTER>
1487 : std::true_type {};
1493#define Q_DECLARE_METATYPE_IMPL(TYPE)
1496 struct QMetaTypeId< TYPE >
1498 enum { Defined = 1
};
1499 static_assert(QtPrivate::checkTypeIsSuitableForMetaType<TYPE>());
1500 static int qt_metatype_id()
1502 Q_CONSTINIT static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0
);
1503 if (const int id = metatype_id.loadAcquire())
1505 constexpr auto arr = QtPrivate::typenameHelper<TYPE>();
1506 auto name = arr.data();
1507 if (QByteArrayView(name) == (#TYPE)) {
1508 const int id = qRegisterNormalizedMetaType<TYPE>(name);
1509 metatype_id.storeRelease(id);
1512 const int newId = qRegisterMetaType< TYPE >(#TYPE);
1513 metatype_id.storeRelease(newId);
1520#define Q_DECLARE_BUILTIN_METATYPE(TYPE, METATYPEID, NAME)
1522 template<> struct QMetaTypeId2<NAME>
1524 using NameAsArrayType = std::array<char, sizeof(#NAME)>;
1525 enum { Defined = 1
, IsBuiltIn = true, MetaType = METATYPEID };
1526 static inline constexpr int qt_metatype_id() { return METATYPEID; }
1527 static constexpr NameAsArrayType nameAsArray = { #NAME };
1531#define QT_FORWARD_DECLARE_STATIC_TYPES_ITER(TypeName, TypeId, Name)
1538#undef QT_FORWARD_DECLARE_STATIC_TYPES_ITER
1540#define Q_DECLARE_METATYPE_TEMPLATE_1ARG(SINGLE_ARG_TEMPLATE) QT_BEGIN_NAMESPACE
1543 QMetaTypeId< SINGLE_ARG_TEMPLATE<T> > \
1544{
1546 Defined = QMetaTypeId2<T>::Defined
1548 static int qt_metatype_id()
1550 Q_CONSTINIT static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0
);
1551 if (const int id = metatype_id.loadRelaxed())
1553 const char *tName = QMetaType::fromType<T>().name();
1555 const size_t tNameLen = qstrlen(tName);
1556 QByteArray typeName;
1557 typeName.reserve(sizeof(#SINGLE_ARG_TEMPLATE) + 1
+ tNameLen + 1
+ 1
);
1558 typeName.append(#SINGLE_ARG_TEMPLATE, int(sizeof(#SINGLE_ARG_TEMPLATE)) - 1
)
1559 .append('<').append(tName, tNameLen);
1560 typeName.append('>');
1561 const int newId = qRegisterNormalizedMetaType< SINGLE_ARG_TEMPLATE<T> >(typeName);
1562 metatype_id.storeRelease(newId);
1565};QT_END_NAMESPACE
1568#define Q_DECLARE_METATYPE_TEMPLATE_2ARG(DOUBLE_ARG_TEMPLATE) QT_BEGIN_NAMESPACE
1570 <typename T, typename U> struct
1571 QMetaTypeId< DOUBLE_ARG_TEMPLATE<T, U> > \
1572{
1574 Defined = QMetaTypeId2<T>::Defined && QMetaTypeId2<U>::Defined
1576 static int qt_metatype_id()
1578 Q_CONSTINIT static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0
);
1579 if (const int id = metatype_id.loadAcquire())
1581 const char *tName = QMetaType::fromType<T>().name();
1582 const char *uName = QMetaType::fromType<U>().name();
1585 const size_t tNameLen = qstrlen(tName);
1586 const size_t uNameLen = qstrlen(uName);
1587 QByteArray typeName;
1588 typeName.reserve(sizeof(#DOUBLE_ARG_TEMPLATE) + 1
+ tNameLen + 1
+ uNameLen + 1
+ 1
);
1589 typeName.append(#DOUBLE_ARG_TEMPLATE, int(sizeof(#DOUBLE_ARG_TEMPLATE)) - 1
)
1590 .append('<').append(tName, tNameLen).append(',').append(uName, uNameLen);
1591 typeName.append('>');
1592 const int newId = qRegisterNormalizedMetaType< DOUBLE_ARG_TEMPLATE<T, U> >(typeName);
1593 metatype_id.storeRelease(newId);
1596};QT_END_NAMESPACE
1601template<
typename T,
bool =
false>
1615#define Q_DECLARE_SMART_POINTER_METATYPE(SMART_POINTER) QT_BEGIN_NAMESPACE
1617 QtPrivate { template
1619 SharedPointerMetaTypeIdHelper<SMART_POINTER<T>, true> \
1620{
1624 static int qt_metatype_id()
1626 Q_CONSTINIT static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0
);
1627 if (const int id = metatype_id.loadAcquire())
1629 const char * const cName = T::staticMetaObject.className();
1630 QByteArray typeName;
1631 typeName.reserve(sizeof(#SMART_POINTER) + 1
+ strlen(cName) + 1
);
1632 typeName.append(#SMART_POINTER, int(sizeof(#SMART_POINTER)) - 1
)
1633 .append('<').append(cName).append('>');
1634 const int newId = qRegisterNormalizedMetaType< SMART_POINTER<T> >(typeName);
1635 metatype_id.storeRelease(newId);
1638};template
1640 MetaTypeSmartPointerHelper<SMART_POINTER<T> ,
1641 typename std::enable_if<IsPointerToTypeDerivedFromQObject<T*>::Value && !std::is_const_v<T>>::type> \
1642{
1643 static bool registerConverter()
1645 const QMetaType to = QMetaType(QMetaType::QObjectStar);
1646 if (!QMetaType::hasRegisteredConverterFunction(QMetaType::fromType<SMART_POINTER<T>>(), to)) {
1647 QtPrivate::QSmartPointerConvertFunctor<SMART_POINTER<T> > o;
1648 return QMetaType::registerConverter<SMART_POINTER<T>, QObject*>(o);
1652};\
1653}template
1655 QMetaTypeId< SMART_POINTER<T> >
1656 : QtPrivate::SharedPointerMetaTypeIdHelper< SMART_POINTER<T>,
1657 QtPrivate::IsPointerToTypeDerivedFromQObject<T*>::Value> \
1658{\
1659};QT_END_NAMESPACE
1662#define Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(SINGLE_ARG_TEMPLATE)
1664 namespace QtPrivate {
1665 template<typename T>
1666 struct IsSequentialContainer<SINGLE_ARG_TEMPLATE<T> >
1668 enum { Value = true };
1674#define Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE_ITER(TEMPLATENAME)
1681#undef Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE_ITER
1686#define Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE(TEMPLATENAME)
1688 namespace QtPrivate {
1689 template<typename T, typename U>
1690 struct IsAssociativeContainer<TEMPLATENAME<T, U> >
1692 enum { Value = true };
1704#define Q_DECLARE_METATYPE_TEMPLATE_SMART_POINTER_ITER(TEMPLATENAME)
1711#undef Q_DECLARE_METATYPE_TEMPLATE_SMART_POINTER_ITER
1729template <
typename T>
1734 return QMetaType::registerConverter<T, QtMetaTypePrivate::QPairVariantInterfaceImpl>(o);
1741template<
typename From>
1746 return QIterable<
QMetaSequence>(QMetaSequence::fromContainer<From>(), &f);
1750template<
typename From>
1755 return QIterable<
QMetaSequence>(QMetaSequence::fromContainer<From>(), &f);
1766 return QMetaType::registerConverter<T, QIterable<QMetaSequence>>(o);
1775 return QMetaType::registerMutableView<T, QIterable<QMetaSequence>>(o);
1781template<
typename From>
1786 return QIterable<
QMetaAssociation>(QMetaAssociation::fromContainer<From>(), &f);
1790template<
typename From>
1795 return QIterable<
QMetaAssociation>(QMetaAssociation::fromContainer<From>(), &f);
1808 return QMetaType::registerConverter<T, QIterable<QMetaAssociation>>(o);
1817 return QMetaType::registerMutableView<T, QIterable<QMetaAssociation>>(o);
1830 static constexpr bool is_ident_char(
char s)
1832 return ((s >=
'a' && s <=
'z') || (s >=
'A' && s <=
'Z') || (s >=
'0' && s <=
'9')
1835 static constexpr bool is_space(
char s) {
return (s ==
' ' || s ==
'\t' || s ==
'\n'); }
1836 static constexpr bool is_number(
char s) {
return s >=
'0' && s <=
'9'; }
1837 static constexpr bool starts_with_token(
const char *b,
const char *e,
const char *token,
1838 bool msvcKw =
false)
1840 while (b != e && *token && *b == *token) {
1849 if (msvcKw && !is_ident_char(*b))
1853 return b == e || !is_ident_char(*b);
1855 static constexpr bool skipToken(
const char *&x,
const char *e,
const char *token,
1856 bool msvcKw =
false)
1858 if (!starts_with_token(x, e, token, msvcKw))
1862 while (x != e && is_space(*x))
1866 static constexpr const char *skipString(
const char *x,
const char *e)
1870 while (x != e && *x != delim) {
1882 static constexpr const char *skipTemplate(
const char *x,
const char *e,
bool stopAtComa =
false)
1885 int templateDepth = 0;
1893 if (stopAtComa && !scopeDepth && !templateDepth)
1898 if (--templateDepth < 0)
1912 if (is_number(x[-1]))
1916 x = skipString(x, e);
1924 constexpr void append(
char x)
1932 constexpr void replaceLast(
char x)
1939 constexpr void appendStr(
const char *x)
1945 constexpr void normalizeIntegerTypes(
const char *&begin,
const char *end)
1949 int numUnsigned = 0;
1953 while (begin < end) {
1954 if (skipToken(begin, end,
"long")) {
1958 if (skipToken(begin, end,
"int")) {
1962 if (skipToken(begin, end,
"short")) {
1966 if (skipToken(begin, end,
"unsigned")) {
1970 if (skipToken(begin, end,
"signed")) {
1974 if (skipToken(begin, end,
"char")) {
1979 if (skipToken(begin, end,
"__int64")) {
1988 if (numSigned && numChar)
1989 appendStr(
"signed ");
1990 else if (numUnsigned)
1996 else if (numLong == 1)
1998 else if (numLong == 2)
1999 appendStr(
"longlong");
2000 else if (numUnsigned || numSigned || numInt)
2004 constexpr void skipStructClassOrEnum(
const char *&begin,
const char *end)
2008 skipToken(begin, end,
"struct",
true) || skipToken(begin, end,
"class",
true)
2009 || skipToken(begin, end,
"enum",
true);
2012 constexpr void skipQtNamespace(
const char *&begin,
const char *end)
2015 const char *nsbeg = begin;
2016 if (skipToken(nsbeg, end, QT_STRINGIFY(QT_NAMESPACE)) && nsbeg + 2 < end && nsbeg[0] ==
':'
2017 && nsbeg[1] ==
':') {
2019 while (begin != end && is_space(*begin))
2029#if defined(Q_CC_CLANG) || defined (Q_CC_GNU)
2037#if defined (Q_CC_CLANG)
2044 if (*
begin ==
' ') {
2082 constexpr int normalizeType(
const char *begin,
const char *end,
bool adjustConst =
true)
2085 while (begin != end && is_space(*begin))
2087 while (begin != end && is_space(*(end - 1)))
2095 const char *cst = begin + 1;
2096 if (*begin ==
'\'' || *begin ==
'"')
2097 cst = skipString(begin, end);
2098 bool seenStar =
false;
2099 bool hasMiddleConst =
false;
2101 if (*cst ==
'\"' || (*cst ==
'\'' && !is_number(cst[-1]))) {
2102 cst = skipString(cst, end);
2109 if (*cst ==
'&' || *cst ==
'*' || *cst ==
'[') {
2110 seenStar = *cst !=
'&' || cst != (end - 1);
2114 cst = skipTemplate(cst + 1, end);
2119 const char *skipedCst = cst;
2120 if (!is_ident_char(*(cst - 1)) && skipToken(skipedCst, end,
"const")) {
2121 const char *testEnd = end;
2122 while (skipedCst < testEnd--) {
2123 if (*testEnd ==
'*' || *testEnd ==
'['
2124 || (*testEnd ==
'&' && testEnd != (end - 1))) {
2128 if (*testEnd ==
'>')
2131 if (adjustConst && !seenStar) {
2132 if (*(end - 1) ==
'&')
2135 appendStr(
"const ");
2139 hasMiddleConst =
true;
2143 if (skipToken(begin, end,
"const")) {
2144 if (adjustConst && !seenStar) {
2145 if (*(end - 1) ==
'&')
2148 appendStr(
"const ");
2151 if (seenStar && adjustConst) {
2152 const char *e = end;
2153 if (*(end - 1) ==
'&' && *(end - 2) !=
'&')
2155 while (begin != e && is_space(*(e - 1)))
2157 const char *token =
"tsnoc";
2158 while (*token && begin != e && *(--e) == *token++)
2160 if (!*token && begin != e && !is_ident_char(*(e - 1))) {
2161 while (begin != e && is_space(*(e - 1)))
2167 skipStructClassOrEnum(begin, end);
2168 skipQtNamespace(begin, end);
2170 if (skipToken(begin, end,
"QVector")) {
2175 if (skipToken(begin, end,
"QPair")) {
2177 appendStr(
"std::pair");
2180 if (!hasMiddleConst)
2182 normalizeIntegerTypes(begin, end);
2184 bool spaceSkiped =
true;
2185 while (begin != end) {
2189 }
else if ((c ==
'\'' && !is_number(
last)) || c ==
'\"') {
2191 auto x = skipString(begin, end);
2195 if (spaceSkiped && is_ident_char(
last) && is_ident_char(c))
2198 spaceSkiped =
false;
2202 const char *tpl = skipTemplate(begin, end,
true);
2208 }
while (*begin++ ==
',');
2227template <
typename T1_,
typename T2_>
2240 std::remove_const_t<std::conditional_t<
bool (QMetaTypeId2<T1>::IsBuiltIn),
typename QMetaTypeId2<T1>::NameAsArrayType,
decltype(typenameHelper<T1>())>> t1Name {};
2241 std::remove_const_t<std::conditional_t<
bool (QMetaTypeId2<T2>::IsBuiltIn),
typename QMetaTypeId2<T2>::NameAsArrayType,
decltype(typenameHelper<T2>())>> t2Name {};
2245 t1Name = typenameHelper<T1>();
2250 t2Name = typenameHelper<T2>();
2252 constexpr auto nonTypeDependentLen =
sizeof(
"std::pair<,>");
2253 constexpr auto t1Len = t1Name.size() - 1;
2254 constexpr auto t2Len = t2Name.size() - 1;
2255 constexpr auto length = nonTypeDependentLen + t1Len + t2Len;
2256 std::array<
char, length + 1> result {};
2257 constexpr auto prefix =
"std::pair<";
2258 int currentLength = 0;
2259 for (; currentLength <
int(
sizeof(
"std::pair<") - 1); ++currentLength)
2260 result[currentLength] = prefix[currentLength];
2261 for (
int i = 0; i <
int(t1Len); ++currentLength, ++i)
2262 result[currentLength] = t1Name[i];
2263 result[currentLength++] =
',';
2264 for (
int i = 0; i <
int(t2Len); ++currentLength, ++i)
2265 result[currentLength] = t2Name[i];
2266 result[currentLength++] =
'>';
2267 result[currentLength++] =
'\0';
2270 constexpr auto prefix =
sizeof(
2272 QT_STRINGIFY(QT_NAMESPACE)
"::"
2274#if defined(Q_CC_MSVC) && defined(Q_CC_CLANG)
2275 "auto __cdecl QtPrivate::TypeNameHelper::typenameHelper(void) [T = "
2276#elif defined(Q_CC_MSVC)
2277 "auto __cdecl QtPrivate::TypeNameHelper::typenameHelper<"
2278#elif defined(Q_CC_CLANG)
2279 "auto QtPrivate::TypeNameHelper::typenameHelper() [T = "
2280#elif defined(Q_CC_GHS)
2281 "auto QtPrivate::TypeNameHelper::typenameHelper<T>()[with T="
2283 "constexpr auto QtPrivate::TypeNameHelper::typenameHelper() [with T = "
2286#if defined(Q_CC_MSVC) && !defined(Q_CC_CLANG)
2287 constexpr int suffix =
sizeof(
">(void)");
2289 constexpr int suffix =
sizeof(
"]");
2292#if defined(Q_CC_GNU_ONLY) && Q_CC_GNU_ONLY < 804
2293 auto func = Q_FUNC_INFO;
2294 const char *begin = func + prefix;
2295 const char *end = func +
sizeof(Q_FUNC_INFO) - suffix;
2297 constexpr int len =
sizeof(Q_FUNC_INFO) - suffix - prefix;
2299 constexpr auto func = Q_FUNC_INFO;
2300 constexpr const char *begin = func + prefix;
2301 constexpr const char *end = func +
sizeof(Q_FUNC_INFO) - suffix;
2304 std::array<
char, len + 1> result {};
2312template<
typename T,
typename =
void>
2326QT_WARNING_DISABLE_FLOAT_COMPARE
2328 {
return *
reinterpret_cast<
const T *>(
a) == *
reinterpret_cast<
const T *>(
b); }
2342 {
return *
reinterpret_cast<
const T *>(a) < *
reinterpret_cast<
const T *>(b); }
2357#ifndef QT_NO_DEBUG_STREAM
2362 { dbg << *
reinterpret_cast<
const T *>(a); }
2373#ifndef QT_NO_DATASTREAM
2378 { ds << *
reinterpret_cast<
const T *>(a); }
2380 { ds >> *
reinterpret_cast<T *>(a); }
2394#if !defined(Q_OS_WIN) && defined(Q_CC_CLANG)
2395# pragma GCC visibility push(hidden)
2404 template <
typename T>
2407#if !defined(QT_BOOTSTRAPPED)
2416 static constexpr decltype(typenameHelper<S>())
name = typenameHelper<S>();
2421 if constexpr (QTypeInfo<S>::isRelocatable)
2422 flags |= QMetaType::RelocatableType;
2423 if constexpr (!std::is_default_constructible_v<S> || !QTypeInfo<S>::isValueInitializationBitwiseZero)
2424 flags |= QMetaType::NeedsConstruction;
2425 if constexpr (!std::is_trivially_destructible_v<S>)
2426 flags |= QMetaType::NeedsDestruction;
2427 if constexpr (!std::is_trivially_copy_constructible_v<S>)
2428 flags |= QMetaType::NeedsCopyConstruction;
2429 if constexpr (!std::is_trivially_move_constructible_v<S>)
2430 flags |= QMetaType::NeedsMoveConstruction;
2431 if constexpr (IsPointerToTypeDerivedFromQObject<S>::Value)
2432 flags |= QMetaType::PointerToQObject;
2433 if constexpr (IsSharedPointerToTypeDerivedFromQObject<S>::Value)
2434 flags |= QMetaType::SharedPointerToQObject;
2435 if constexpr (IsWeakPointerToTypeDerivedFromQObject<S>::Value)
2436 flags |= QMetaType::WeakPointerToQObject;
2437 if constexpr (IsTrackingPointerToTypeDerivedFromQObject<S>::Value)
2438 flags |= QMetaType::TrackingPointerToQObject;
2439 if constexpr (IsEnumOrFlags<S>::value)
2440 flags |= QMetaType::IsEnumeration;
2441 if constexpr (IsGadgetHelper<S>::IsGadgetOrDerivedFrom)
2442 flags |= QMetaType::IsGadget;
2443 if constexpr (IsPointerToGadgetHelper<S>::IsGadgetOrDerivedFrom)
2444 flags |= QMetaType::PointerToGadget;
2445 if constexpr (std::is_pointer_v<S>)
2446 flags |= QMetaType::IsPointer;
2447 if constexpr (IsUnsignedEnum<S>)
2448 flags |= QMetaType::IsUnsignedEnumeration;
2449 if constexpr (IsQmlListType<S>)
2450 flags |= QMetaType::IsQmlList;
2451 if constexpr (std::is_const_v<std::remove_pointer_t<S>>)
2452 flags |= QMetaType::IsConst;
2458 if constexpr (std::is_default_constructible_v<S> && !QTypeInfo<S>::isValueInitializationBitwiseZero) {
2467 if constexpr (
std::is_copy_constructible_v<S> && !
std::is_trivially_copy_constructible_v<S>) {
2469 if constexpr (qxp::is_detected_v<QMetaTypeCopyTraits::HasDeprecatedCopyConstructorTest, S>) {
2470#if !defined(QT_BOOTSTRAPPED)
2473 QT_IGNORE_DEPRECATIONS(
new (addr) S(*
reinterpret_cast<
const S *>(other));)
2475 new (addr) S(*
reinterpret_cast<
const S *>(other));
2485 if constexpr (
std::is_move_constructible_v<S> && !
std::is_trivially_move_constructible_v<S>) {
2487 new (addr) S(
std::move(*
reinterpret_cast<S *>(other)));
2496 if constexpr (
std::is_destructible_v<S> && !
std::is_trivially_destructible_v<S>)
2498 reinterpret_cast<S *>(addr)->~S();
2555#if !defined(Q_OS_WIN) && defined(Q_CC_CLANG)
2556# pragma GCC visibility pop
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595#if !defined(QT_BOOTSTRAPPED) && !defined(Q_CC_MSVC) && !defined(Q_OS_INTEGRITY)
2597#ifdef QT_NO_DATA_RELOCATION
2598# define QT_METATYPE_DECLARE_EXTERN_TEMPLATE_ITER(TypeName, Id, Name)
2599 extern template class Q_CORE_EXPORT QMetaTypeForType<Name>;
2601# define QT_METATYPE_DECLARE_EXTERN_TEMPLATE_ITER(TypeName, Id, Name)
2602 extern template class Q_CORE_EXPORT QMetaTypeForType<Name>;
2603 extern template struct Q_CORE_EXPORT QMetaTypeInterfaceWrapper<Name>;
2611#undef QT_METATYPE_DECLARE_EXTERN_TEMPLATE_ITER
2620#define Q_REMOVE_POINTER_LIKE_IMPL(Pointer) template
2622 QRemovePointerLike<Pointer<T>> \
2623{
2625};
2628#undef Q_REMOVE_POINTER_LIKE_IMPL
2643template<
typename Unique,
typename T>
2649 if constexpr (
std::is_void_v<Tz>) {
2652 }
else if constexpr (
std::is_void_v<Unique>) {
2653 checkTypeIsSuitableForMetaType<Ty>();
2655 }
else if constexpr (
std::is_reference_v<Tz>) {
2657 }
else if constexpr (!
is_complete<Tz, Unique>::value) {
2668constexpr QMetaType QMetaType::fromType()
2670 QtPrivate::checkTypeIsSuitableForMetaType<T>();
2671 return QMetaType(QtPrivate::qMetaTypeInterfaceForType<T>());
2674template <
typename T>
bool
2675QMetaType::isSameTypeHelper(
const QtPrivate::QMetaTypeInterface *iface, std::true_type)
const noexcept
2678 constexpr int Id =
int(QMetaTypeId2<T>::MetaType);
2680#ifdef QT_NO_DATA_RELOCATION
2683 if constexpr (!std::is_void_v<T> && QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)) {
2687 if constexpr (Id <=
int(LastCoreType))
2688 return d_ptr == iface;
2700 return d_ptr->typeId.loadRelaxed() == Id;
2703template <
typename T>
bool
2704QMetaType::isSameTypeHelper(
const QtPrivate::QMetaTypeInterface *iface, std::false_type)
const
2710 return *
this == QMetaType(iface);
2713constexpr bool QMetaType::isValid(QT6_IMPL_NEW_OVERLOAD)
const noexcept
2718bool QMetaType::isRegistered(QT6_IMPL_NEW_OVERLOAD)
const noexcept
2720 return d_ptr && Q_LIKELY(d_ptr->typeId.loadRelaxed());
2723constexpr qsizetype QMetaType::sizeOf()
const
2725 return d_ptr ? d_ptr->size : 0;
2728constexpr qsizetype QMetaType::alignOf()
const
2730 return d_ptr ? d_ptr->alignment : 0;
2733constexpr QMetaType::TypeFlags QMetaType::flags()
const
2735 return d_ptr ? TypeFlags(d_ptr->flags) : TypeFlags{};
2738constexpr const QMetaObject *QMetaType::metaObject()
const
2740 return d_ptr && d_ptr->metaObjectFn ? d_ptr->metaObjectFn(d_ptr) :
nullptr;
2743constexpr const char *QMetaType::name()
const
2745 return d_ptr ? d_ptr->name :
nullptr;
2752 return qHash(type.id(), seed);
2758 QPairVariantInterfaceImpl, Q_CORE_EXPORT)
Combined button and popup list for selecting options.
constexpr auto typenameHelper()
Q_CORE_EXPORT bool hasRegisteredConverterFunctionToIterableMetaSequence(QMetaType m)
Q_CORE_EXPORT bool hasRegisteredMutableViewFunctionToIterableMetaSequence(QMetaType m)
static constexpr bool checkTypeIsSuitableForMetaType()
constexpr bool IsQmlListType
constexpr int qNormalizeType(const char *begin, const char *end, char *output)
constexpr bool IsUnsignedEnum
Q_CORE_EXPORT bool hasRegisteredConverterFunctionToPairVariantInterface(QMetaType m)
constexpr const QMetaTypeInterface * qTryMetaTypeInterfaceForType()
constexpr bool IsUnsignedEnum< T, true >
Q_CORE_EXPORT bool hasRegisteredConverterFunctionToIterableMetaAssociation(QMetaType m)
Q_CORE_EXPORT bool hasRegisteredMutableViewFunctionToIterableMetaAssociation(QMetaType m)
To convertImplicit(const From &from)
This template is used for implicit conversion from type From to type To.
constexpr const QMetaTypeInterface * qMetaTypeInterfaceForType()
char qt_getEnumMetaObject(const T &)
static void * checkType(void(T::*)())
static char checkType(void(X::*)())
static bool registerConverter()
static char checkType(void(X::*)())
static void * checkType(void(T::*)())
static no_type checkType(...)
static yes_type checkType(QObject *)
static yes_type checkType(const QObject *)
static const T & declval()
QIterable< QMetaAssociation > operator()(const From &f) const
QIterable< QMetaAssociation > operator()(From &f) const
static void dataStreamIn(const QMetaTypeInterface *, QDataStream &ds, void *a)
static void dataStreamOut(const QMetaTypeInterface *, QDataStream &ds, const void *a)
static void debugStream(const QMetaTypeInterface *, QDebug &dbg, const void *a)
static constexpr QMetaTypeInterface::DebugStreamFn debugStream
static constexpr QMetaTypeInterface::EqualsFn equals
static constexpr QMetaTypeInterface::LessThanFn lessThan
static bool lessThan(const QMetaTypeInterface *, const void *a, const void *b)
QIterable< QMetaSequence > operator()(const From &f) const
QIterable< QMetaSequence > operator()(From &f) const
QObject * operator()(const QWeakPointer< T > &p) const
QObject * operator()(const SmartPointer &p) const
constexpr int normalizeType(const char *begin, const char *end, bool adjustConst=true)
constexpr int normalizeTypeFromSignature(const char *begin, const char *end)
static auto check(...) -> std::false_type
static auto check(U *) -> std::integral_constant< bool, sizeof(U) !=0 >
decltype(check(static_cast< T * >(nullptr))) type