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>
366 template <
typename T,
typename UniqueType =
void>
constexpr inline
368 template <
typename T>
constexpr inline
372 template <
typename T,
typename UniqueType =
void>
constexpr inline
381 static_assert(TypeIsCompleteOrVoid<T>,
"Meta Types must be fully defined");
382 static_assert(!
std::is_reference_v<T>,
383 "Meta Types cannot be non-const references or rvalue references.");
384 if constexpr (
std::is_pointer_v<T>) {
385 static_assert(PointerIsSuitableForMetaTypeHelper<T>,
386 "Pointer Meta Types must either point to fully-defined types "
387 "or be declared with Q_DECLARE_OPAQUE_POINTER(T *)");
390 static_assert(TypeIsSuitableForMetaType<T>);
403 FirstCoreType = Bool,
404 LastCoreType = Float16,
405 FirstGuiType = QFont,
406 LastGuiType = QColorSpace,
407 FirstWidgetsType = QSizePolicy,
408 LastWidgetsType = QSizePolicy,
409 HighestInternalId = LastWidgetsType,
411 QReal =
sizeof(qreal) ==
sizeof(
double) ? Double : Float,
419 UnknownType = 0, Bool = 1, Int = 2, UInt = 3, LongLong = 4, ULongLong = 5,
420 Double = 6, Long = 32, Short = 33, Char = 34, ULong = 35, UShort = 36,
421 UChar = 37, Float = 38,
423 QChar = 7, QString = 10, QStringList = 11, QByteArray = 12,
424 QBitArray = 13, QDate = 14, QTime = 15, QDateTime = 16, QUrl = 17,
425 QLocale = 18, QRect = 19, QRectF = 20, QSize = 21, QSizeF = 22,
426 QLine = 23, QLineF = 24, QPoint = 25, QPointF = 26,
427 QEasingCurve = 29, QUuid = 30, QVariant = 41, QModelIndex = 42,
428 QPersistentModelIndex = 50, QRegularExpression = 44,
429 QJsonValue = 45, QJsonObject = 46, QJsonArray = 47, QJsonDocument = 48,
430 QByteArrayList = 49, QObjectStar = 39, SChar = 40,
433 QVariantMap = 8, QVariantList = 9, QVariantHash = 28, QVariantPair = 58,
434 QCborSimpleType = 52, QCborValue = 53, QCborArray = 54, QCborMap = 55,
435 Char16 = 56, Char32 = 57,
436 Int128 = 59, UInt128 = 60, Float128 = 61, BFloat16 = 62, Float16 = 63,
439 QFont = 0x1000, QPixmap = 0x1001, QBrush = 0x1002, QColor = 0x1003, QPalette = 0x1004,
440 QIcon = 0x1005, QImage = 0x1006, QPolygon = 0x1007, QRegion = 0x1008, QBitmap = 0x1009,
441 QCursor = 0x100a, QKeySequence = 0x100b, QPen = 0x100c, QTextLength = 0x100d, QTextFormat = 0x100e,
442 QTransform = 0x1010, QMatrix4x4 = 0x1011, QVector2D = 0x1012,
443 QVector3D = 0x1013, QVector4D = 0x1014, QQuaternion = 0x1015, QPolygonF = 0x1016, QColorSpace = 0x1017,
446 QSizePolicy = 0x2000,
454 NeedsConstruction = 0x1,
455 NeedsDestruction = 0x2,
456 RelocatableType = 0x4,
457#if QT_DEPRECATED_SINCE(6
, 0
)
458 MovableType Q_DECL_ENUMERATOR_DEPRECATED_X(
"Use RelocatableType instead.") = RelocatableType,
460 PointerToQObject = 0x8,
461 IsEnumeration = 0x10,
462 SharedPointerToQObject = 0x20,
463 WeakPointerToQObject = 0x40,
464 TrackingPointerToQObject = 0x80,
465 IsUnsignedEnumeration = 0x100,
467 PointerToGadget = 0x400,
472 NeedsCopyConstruction = 0x4000,
473 NeedsMoveConstruction = 0x8000,
475 Q_DECLARE_FLAGS(TypeFlags, TypeFlag)
477 static void registerNormalizedTypedef(
const QT_PREPEND_NAMESPACE(QByteArray) &normalizedTypeName, QMetaType type);
479#if QT_DEPRECATED_SINCE(6
, 0
)
480 QT_DEPRECATED_VERSION_6_0
481 static int type(
const char *typeName)
482 {
return QMetaType::fromName(typeName).rawId(); }
483 QT_DEPRECATED_VERSION_6_0
484 static int type(
const QT_PREPEND_NAMESPACE(QByteArray) &typeName)
485 {
return QMetaType::fromName(typeName).rawId(); }
486 QT_DEPRECATED_VERSION_6_0
487 static const char *typeName(
int type)
488 {
return QMetaType(type).name(); }
489 QT_DEPRECATED_VERSION_6_0
490 static int sizeOf(
int type)
491 {
return int(QMetaType(type).sizeOf()); }
492 QT_DEPRECATED_VERSION_6_0
493 static TypeFlags typeFlags(
int type)
494 {
return QMetaType(type).flags(); }
495 QT_DEPRECATED_VERSION_6_0
496 static const QMetaObject *metaObjectForType(
int type)
497 {
return QMetaType(type).metaObject(); }
498 QT_DEPRECATED_VERSION_6_0
499 static void *create(
int type,
const void *copy =
nullptr)
500 {
return QMetaType(type).create(copy); }
501 QT_DEPRECATED_VERSION_6_0
502 static void destroy(
int type,
void *data)
503 {
return QMetaType(type).destroy(data); }
504 QT_DEPRECATED_VERSION_6_0
505 static void *construct(
int type,
void *where,
const void *copy)
506 {
return QMetaType(type).construct(where, copy); }
507 QT_DEPRECATED_VERSION_6_0
508 static void destruct(
int type,
void *where)
509 {
return QMetaType(type).destruct(where); }
511 static bool isRegistered(
int type);
513 explicit QMetaType(
int type);
514 explicit constexpr QMetaType(
const QtPrivate::QMetaTypeInterface *d) : d_ptr(d) {}
515 constexpr QMetaType() =
default;
517#if QT_CORE_REMOVED_SINCE(6
, 9
)
518 bool isValid()
const;
519 bool isRegistered()
const;
521 constexpr bool isValid(QT6_DECL_NEW_OVERLOAD)
const noexcept;
522 inline bool isRegistered(QT6_DECL_NEW_OVERLOAD)
const noexcept;
523 void registerType()
const
528#if QT_CORE_REMOVED_SINCE(6
, 1
) || defined(Q_QDOC)
533 int id(
int = 0)
const
535 return registerHelper();
540 Q_PRE(!isValid(QT6_CALL_NEW_OVERLOAD) || isRegistered(QT6_CALL_NEW_OVERLOAD));
541 return d_ptr ? d_ptr->typeId.loadRelaxed() : 0;
544 template <
typename Type>
constexpr bool isSameType()
const
546 using T =
typename QtPrivate::MetatypeDecay<Type>::type;
547 QMetaType other = fromType<T>();
548 if (q20::is_constant_evaluated()) {
551 return d_ptr == other.iface();
553 using IsBuiltIn = std::bool_constant<QMetaTypeId2<T>::IsBuiltIn>;
554 return isSameTypeHelper<T>(other.iface(), IsBuiltIn{});
558 constexpr qsizetype sizeOf()
const;
559 constexpr qsizetype alignOf()
const;
560 constexpr TypeFlags flags()
const;
561 constexpr const QMetaObject *metaObject()
const;
562 constexpr const char *name()
const;
564 void *create(
const void *copy =
nullptr)
const;
565 void destroy(
void *data)
const;
566 void *construct(
void *where,
const void *copy =
nullptr)
const;
567 void destruct(
void *data)
const;
568 QPartialOrdering compare(
const void *lhs,
const void *rhs)
const;
569 bool equals(
const void *lhs,
const void *rhs)
const;
571 bool isDefaultConstructible()
const noexcept {
return d_ptr && isDefaultConstructible(d_ptr); }
572 bool isCopyConstructible()
const noexcept {
return d_ptr && isCopyConstructible(d_ptr); }
573 bool isMoveConstructible()
const noexcept {
return d_ptr && isMoveConstructible(d_ptr); }
574 bool isDestructible()
const noexcept {
return d_ptr && isDestructible(d_ptr); }
575 bool isEqualityComparable()
const;
576 bool isOrdered()
const;
578#ifndef QT_NO_DATASTREAM
579 bool save(QDataStream &stream,
const void *data)
const;
580 bool load(QDataStream &stream,
void *data)
const;
581 bool hasRegisteredDataStreamOperators()
const;
583#if QT_DEPRECATED_SINCE(6
, 0
)
584 QT_DEPRECATED_VERSION_6_0
585 static bool save(QDataStream &stream,
int type,
const void *data)
586 {
return QMetaType(type).save(stream, data); }
587 QT_DEPRECATED_VERSION_6_0
588 static bool load(QDataStream &stream,
int type,
void *data)
589 {
return QMetaType(type).load(stream, data); }
593 QMetaType underlyingType()
const;
596 constexpr static QMetaType fromType();
597 static QMetaType fromName(QByteArrayView name);
599 friend bool comparesEqual(
const QMetaType &lhs,
600 const QMetaType &rhs)
602 if (lhs.d_ptr == rhs.d_ptr)
604 if (!lhs.d_ptr || !rhs.d_ptr)
607 const int aId = lhs.id();
608 const int bId = rhs.id();
611 Q_DECLARE_EQUALITY_COMPARABLE_NON_NOEXCEPT(QMetaType)
612#ifndef QT_NO_DEBUG_STREAM
614 friend Q_CORE_EXPORT QDebug operator<<(QDebug d, QMetaType m);
616 bool debugStream(QDebug& dbg,
const void *rhs);
617 bool hasRegisteredDebugStreamOperator()
const;
619#if QT_DEPRECATED_SINCE(6
, 0
)
620 QT_DEPRECATED_VERSION_6_0
621 static bool debugStream(QDebug& dbg,
const void *rhs,
int typeId)
622 {
return QMetaType(typeId).debugStream(dbg, rhs); }
624 QT_DEPRECATED_VERSION_6_0
625 static bool hasRegisteredDebugStreamOperator()
626 {
return QMetaType::fromType<T>().hasRegisteredDebugStreamOperator(); }
627 QT_DEPRECATED_VERSION_6_0
628 static bool hasRegisteredDebugStreamOperator(
int typeId)
629 {
return QMetaType(typeId).hasRegisteredDebugStreamOperator(); }
635 using ConverterFunction = std::function<
bool(
const void *src,
void *target)>;
638 using MutableViewFunction = std::function<
bool(
void *src,
void *target)>;
641 template<
typename From,
typename To>
642 static bool registerConverter()
644 return registerConverter<From, To>(QtPrivate::convertImplicit<From, To>);
648 template<
typename From,
typename To>
649 static bool registerConverter(To(From::*function)()
const)
651 static_assert((!QMetaTypeId2<To>::IsBuiltIn || !QMetaTypeId2<From>::IsBuiltIn),
652 "QMetaType::registerConverter: At least one of the types must be a custom type.");
654 const QMetaType fromType = QMetaType::fromType<From>();
655 const QMetaType toType = QMetaType::fromType<To>();
656 auto converter = [function](
const void *from,
void *to) ->
bool {
657 const From *f =
static_cast<
const From *>(from);
658 To *t =
static_cast<To *>(to);
659 *t = (f->*function)();
662 return registerConverterImpl<From, To>(converter, fromType, toType);
666 template<
typename From,
typename To>
667 static bool registerMutableView(To(From::*function)())
669 static_assert((!QMetaTypeId2<To>::IsBuiltIn || !QMetaTypeId2<From>::IsBuiltIn),
670 "QMetaType::registerMutableView: At least one of the types must be a custom type.");
672 const QMetaType fromType = QMetaType::fromType<From>();
673 const QMetaType toType = QMetaType::fromType<To>();
674 auto view = [function](
void *from,
void *to) ->
bool {
675 From *f =
static_cast<From *>(from);
676 To *t =
static_cast<To *>(to);
677 *t = (f->*function)();
680 return registerMutableViewImpl<From, To>(view, fromType, toType);
684 template<
typename From,
typename To>
685 static bool registerConverter(To(From::*function)(
bool*)
const)
687 static_assert((!QMetaTypeId2<To>::IsBuiltIn || !QMetaTypeId2<From>::IsBuiltIn),
688 "QMetaType::registerConverter: At least one of the types must be a custom type.");
690 const QMetaType fromType = QMetaType::fromType<From>();
691 const QMetaType toType = QMetaType::fromType<To>();
692 auto converter = [function](
const void *from,
void *to) ->
bool {
693 const From *f =
static_cast<
const From *>(from);
694 To *t =
static_cast<To *>(to);
696 *t = (f->*function)(&result);
701 return registerConverterImpl<From, To>(converter, fromType, toType);
705 template<
typename From,
typename To,
typename UnaryFunction>
706 static bool registerConverter(UnaryFunction function)
708 static_assert((!QMetaTypeId2<To>::IsBuiltIn || !QMetaTypeId2<From>::IsBuiltIn),
709 "QMetaType::registerConverter: At least one of the types must be a custom type.");
711 const QMetaType fromType = QMetaType::fromType<From>();
712 const QMetaType toType = QMetaType::fromType<To>();
713 auto converter = [function = std::move(function)](
const void *from,
void *to) ->
bool {
714 const From *f =
static_cast<
const From *>(from);
715 To *t =
static_cast<To *>(to);
716 decltype(
auto) r = function(*f);
717 if constexpr (std::is_same_v<q20::remove_cvref_t<
decltype(r)>, std::optional<To>>) {
720 *t = *std::forward<
decltype(r)>(r);
722 *t = std::forward<
decltype(r)>(r);
726 return registerConverterImpl<From, To>(std::move(converter), fromType, toType);
730 template<
typename From,
typename To,
typename UnaryFunction>
731 static bool registerMutableView(UnaryFunction function)
733 static_assert((!QMetaTypeId2<To>::IsBuiltIn || !QMetaTypeId2<From>::IsBuiltIn),
734 "QMetaType::registerMutableView: At least one of the types must be a custom type.");
736 const QMetaType fromType = QMetaType::fromType<From>();
737 const QMetaType toType = QMetaType::fromType<To>();
738 auto view = [function = std::move(function)](
void *from,
void *to) ->
bool {
739 From *f =
static_cast<From *>(from);
740 To *t =
static_cast<To *>(to);
744 return registerMutableViewImpl<From, To>(std::move(view), fromType, toType);
748 template<
typename From,
typename To>
749 static bool registerConverterImpl(ConverterFunction converter, QMetaType fromType, QMetaType toType)
751 if (registerConverterFunction(std::move(converter), fromType, toType)) {
752 static const auto unregister = qScopeGuard([=] {
753 unregisterConverterFunction(fromType, toType);
761 template<
typename From,
typename To>
762 static bool registerMutableViewImpl(MutableViewFunction view, QMetaType fromType, QMetaType toType)
764 if (registerMutableViewFunction(std::move(view), fromType, toType)) {
765 static const auto unregister = qScopeGuard([=] {
766 unregisterMutableViewFunction(fromType, toType);
775 static bool convert(QMetaType fromType,
const void *from, QMetaType toType,
void *to);
776 static bool canConvert(QMetaType fromType, QMetaType toType);
778 static bool view(QMetaType fromType,
void *from, QMetaType toType,
void *to);
779 static bool canView(QMetaType fromType, QMetaType toType);
780#if QT_DEPRECATED_SINCE(6
, 0
)
781 QT_DEPRECATED_VERSION_6_0
782 static bool convert(
const void *from,
int fromTypeId,
void *to,
int toTypeId)
783 {
return convert(QMetaType(fromTypeId), from, QMetaType(toTypeId), to); }
784 QT_DEPRECATED_VERSION_6_0
785 static bool compare(
const void *lhs,
const void *rhs,
int typeId,
int *result)
788 auto c = t.compare(lhs, rhs);
789 if (c == QPartialOrdering::Unordered) {
792 }
else if (c == QPartialOrdering::Less) {
795 }
else if (c == QPartialOrdering::Equivalent) {
803 QT_DEPRECATED_VERSION_6_0
804 static bool equals(
const void *lhs,
const void *rhs,
int typeId,
int *result)
807 if (!t.isEqualityComparable())
809 *result = t.equals(lhs, rhs) ? 0 : -1;
814 template<
typename From,
typename To>
815 static bool hasRegisteredConverterFunction()
817 return hasRegisteredConverterFunction(
818 QMetaType::fromType<From>(), QMetaType::fromType<To>());
821 static bool hasRegisteredConverterFunction(QMetaType fromType, QMetaType toType);
823 template<
typename From,
typename To>
824 static bool hasRegisteredMutableViewFunction()
826 return hasRegisteredMutableViewFunction(
827 QMetaType::fromType<From>(), QMetaType::fromType<To>());
830 static bool hasRegisteredMutableViewFunction(QMetaType fromType, QMetaType toType);
833 template<
typename,
bool>
friend struct QtPrivate::SequentialValueTypeIsMetaType;
834 template<
typename,
bool>
friend struct QtPrivate::AssociativeValueTypeIsMetaType;
835 template<
typename,
bool>
friend struct QtPrivate::IsMetaTypePair;
836 template<
typename,
typename>
friend struct QtPrivate::MetaTypeSmartPointerHelper;
838 static bool registerConverterFunction(
const ConverterFunction &f, QMetaType from, QMetaType to);
839 static void unregisterConverterFunction(QMetaType from, QMetaType to);
841 static bool registerMutableViewFunction(
const MutableViewFunction &f, QMetaType from, QMetaType to);
842 static void unregisterMutableViewFunction(QMetaType from, QMetaType to);
844 static void unregisterMetaType(QMetaType type);
846#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
847 constexpr const QtPrivate::QMetaTypeInterface *iface() {
return d_ptr; }
849 constexpr const QtPrivate::QMetaTypeInterface *iface()
const {
return d_ptr; }
852 Q_DECL_PURE_FUNCTION
static bool isDefaultConstructible(
const QtPrivate::QMetaTypeInterface *)
noexcept;
853 Q_DECL_PURE_FUNCTION
static bool isCopyConstructible(
const QtPrivate::QMetaTypeInterface *)
noexcept;
854 Q_DECL_PURE_FUNCTION
static bool isMoveConstructible(
const QtPrivate::QMetaTypeInterface *)
noexcept;
855 Q_DECL_PURE_FUNCTION
static bool isDestructible(
const QtPrivate::QMetaTypeInterface *)
noexcept;
857 template <
typename T>
bool
858 isSameTypeHelper(
const QtPrivate::QMetaTypeInterface *iface, std::true_type)
const noexcept;
859 template <
typename T>
bool
860 isSameTypeHelper(
const QtPrivate::QMetaTypeInterface *iface, std::false_type)
const;
861#if QT_CORE_REMOVED_SINCE(6
, 5
)
862 int idHelper()
const;
864 static int registerHelper(
const QtPrivate::QMetaTypeInterface *iface);
865 int registerHelper()
const
868 if (
int id = d_ptr->typeId.loadRelaxed(); Q_LIKELY(id))
870 return registerHelper(d_ptr);
875 friend int qRegisterMetaType(QMetaType meta);
877 friend class QVariant;
878 const QtPrivate::QMetaTypeInterface *d_ptr =
nullptr;
881#undef QT_DEFINE_METATYPE_ID
883Q_DECLARE_OPERATORS_FOR_FLAGS(QMetaType::TypeFlags)
885#define QT_METATYPE_PRIVATE_DECLARE_TYPEINFO(C, F)
887 Q_DECLARE_TYPEINFO(QtMetaTypePrivate:: C, (F));
888 namespace QtMetaTypePrivate {
900 typedef void (*
getFunc)(
const void *
const *p,
void *);
907 { *
static_cast<
typename T::first_type *>(dataPtr) =
static_cast<
const T*>(*pair)->first; }
910 { *
static_cast<
typename T::second_type *>(dataPtr) =
static_cast<
const T*>(*pair)->second; }
934template<
typename From>
937template<
typename T,
typename U>
950#define QT_FORWARD_DECLARE_SHARED_POINTER_TYPES_ITER(Name)
951 template <class T> class Name;
994 enum {
Value =
sizeof(checkType(
static_cast<T*>(
nullptr))) ==
sizeof(
yes_type) };
997 template<
typename T,
typename Enable =
void>
1000 template<
typename T>
1003 template <
typename X>
1007 IsRealGadget =
sizeof(checkType(&T::qt_check_for_QGADGET_macro)) ==
sizeof(
void *),
1012 template <
typename T>
1015 template<
typename T,
typename Enable =
void>
1018 template<
typename T>
1022 template <
typename X>
1034 template<
typename T>
1045 template<
typename T,
typename Enable =
void>
1048 static constexpr const QMetaObject *
value() {
return nullptr; }
1052#ifndef QT_NO_QOBJECT
1053 template<
typename T>
1059 template<
typename T>
1070 template<
typename T>
1079 template<
typename T>
1087 template<
typename T>
1093 template<
typename T>
1098 template<
typename T>
1104 template<
typename T>
1109 template<
typename T>
1115 template<
typename T>
1121 template<
typename T>
1127 template<
typename T>
1134
1135
1136
1137
1138
1139
1140
1141 template<
typename T>
1178 template<
typename T>
1225 template<
typename T>
1240 template<
typename T>
1246 template<
typename T>
1254 template<
typename T,
typename U>
1257 template<
typename T>
1260 template<
typename T,
typename =
void>
1266#if QT_CONFIG(future)
1267 template<
typename T>
1276template <
typename T,
int =
1286template <
typename T>
1291template <
typename T>
1299template <
typename T>
1302template <
typename T>
1311 template <
typename T,
bool Defined =
QMetaTypeId2<T>::Defined>
1322 template <
typename Result,
typename... Args>
1325 template<
typename T>
1330 template<
typename T>
1333 template<
typename T,
bool defined>
1339 template<
typename SmartPointer>
1344 return p.operator->();
1350 template <
typename T>
1353 template<
typename T>
1363template <
typename T>
1366#ifndef QT_NO_QOBJECT
1367 Q_ASSERT_X(normalizedTypeName == QMetaObject::normalizedType(normalizedTypeName.constData()),
1368 "qRegisterNormalizedMetaType",
1369 "qRegisterNormalizedMetaType was called with a not normalized type name, "
1370 "please call qRegisterMetaType instead.");
1373 const QMetaType metaType = QMetaType::fromType<T>();
1374 const int id = metaType.id();
1376 QtPrivate::SequentialContainerTransformationHelper<T>::registerConverter();
1377 QtPrivate::SequentialContainerTransformationHelper<T>::registerMutableView();
1378 QtPrivate::AssociativeContainerTransformationHelper<T>::registerConverter();
1379 QtPrivate::AssociativeContainerTransformationHelper<T>::registerMutableView();
1381 QtPrivate::MetaTypeSmartPointerHelper<T>::registerConverter();
1382#if QT_CONFIG(future)
1383 QtPrivate::MetaTypeQFutureHelper<T>::registerConverter();
1386 if (normalizedTypeName != metaType.name())
1387 QMetaType::registerNormalizedTypedef(normalizedTypeName, metaType);
1402template <
typename T>
1405 return qRegisterNormalizedMetaTypeImplementation<T>(normalizedTypeName);
1408#if defined(QT_BOOTSTRAPPED)
1409#define QT_DECL_METATYPE_EXTERN_TAGGED(TYPE, TAG, EXPORT)
1410#define QT_IMPL_METATYPE_EXTERN_TAGGED(TYPE, TAG)
1412#define QT_DECL_METATYPE_EXTERN_TAGGED(TYPE, TAG, EXPORT)
1414 EXPORT int qRegisterNormalizedMetaType_ ## TAG (const QByteArray &);
1415 template <> inline int qRegisterNormalizedMetaType< TYPE >(const QByteArray &name)
1416 { return qRegisterNormalizedMetaType_ ## TAG (name); }
1420#define QT_IMPL_METATYPE_EXTERN_TAGGED(TYPE, TAG)
1421 int qRegisterNormalizedMetaType_ ## TAG (const QByteArray &name)
1422 { return qRegisterNormalizedMetaTypeImplementation< TYPE >(name); }
1425#define QT_DECL_METATYPE_EXTERN(TYPE, EXPORT)
1427#define QT_IMPL_METATYPE_EXTERN(TYPE)
1430template <
typename T>
1434 QT_PREPEND_NAMESPACE(QByteArray) normalizedTypeName = typeName;
1436 QT_PREPEND_NAMESPACE(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName);
1438 return qRegisterNormalizedMetaType<T>(normalizedTypeName);
1441template <
typename T>
1450 return QMetaType::fromType<T>().id();
1454template <
typename T>
1457 int id = qMetaTypeId<T>();
1463 return meta.registerHelper();
1466#ifndef QT_NO_QOBJECT
1467template <
typename T>
1468struct QMetaTypeIdQObject<T*, QMetaType::PointerToGadget>
1474 static int qt_metatype_id()
1477 QMetaType::fromType<std::remove_cv_t<T>>().registerType();
1478 if constexpr (std::is_const_v<T>)
1479 QMetaType::fromType<T>().registerType();
1480 return QMetaType::fromType<T *>().id();
1484template <
typename T>
1485struct QMetaTypeIdQObject<T, QMetaType::IsEnumeration>
1491 static int qt_metatype_id()
1493 Q_CONSTINIT
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0);
1494 if (
const int id = metatype_id.loadAcquire())
1498 const char *eName = qt_getEnumName(T());
1499 const char *cName = qt_getEnumMetaObject(T())->className();
1500 QByteArray typeName;
1501 constexpr bool isConst = std::is_const_v<T>;
1502 typeName.reserve(strlen(cName) + 2 + strlen(eName) + (isConst ? strlen(
"const ") : 0));
1503 if constexpr (isConst)
1504 typeName.append(
"const ");
1505 typeName.append(cName).append(
"::").append(eName);
1506 const int newId = qRegisterNormalizedMetaType<T>(typeName);
1507 metatype_id.storeRelease(newId);
1513#define Q_DECLARE_OPAQUE_POINTER(POINTER)
1514 QT_BEGIN_NAMESPACE namespace QtPrivate {
1515 template <> struct IsPointerDeclaredOpaque<POINTER>
1516 : std::true_type {};
1522#define Q_DECLARE_METATYPE_IMPL(TYPE)
1525 struct QMetaTypeId< TYPE >
1527 enum { Defined = 1
};
1528 static_assert(QtPrivate::checkTypeIsSuitableForMetaType<TYPE>());
1529 static int qt_metatype_id()
1531 Q_CONSTINIT static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0
);
1532 if (const int id = metatype_id.loadAcquire())
1534 constexpr auto arr = QtPrivate::typenameHelper<TYPE>();
1535 auto name = arr.data();
1536 if (QByteArrayView(name) == (#TYPE)) {
1537 const int id = qRegisterNormalizedMetaType<TYPE>(name);
1538 metatype_id.storeRelease(id);
1541 const int newId = qRegisterMetaType< TYPE >(#TYPE);
1542 metatype_id.storeRelease(newId);
1549#define Q_DECLARE_BUILTIN_METATYPE(TYPE, METATYPEID, NAME)
1551 template<> struct QMetaTypeId2<NAME>
1553 using NameAsArrayType = std::array<char, sizeof(#NAME)>;
1554 enum { Defined = 1
, IsBuiltIn = true, MetaType = METATYPEID };
1555 static inline constexpr int qt_metatype_id() { return METATYPEID; }
1556 static constexpr NameAsArrayType nameAsArray = { #NAME };
1560#define QT_FORWARD_DECLARE_STATIC_TYPES_ITER(TypeName, TypeId, Name)
1567#undef QT_FORWARD_DECLARE_STATIC_TYPES_ITER
1569#define Q_DECLARE_METATYPE_TEMPLATE_1ARG(SINGLE_ARG_TEMPLATE) QT_BEGIN_NAMESPACE
1572 QMetaTypeId< SINGLE_ARG_TEMPLATE<T> > \
1573{
1575 Defined = QtPrivate::IsContainerElementWhichNeedsConverter<T>::value
1577 static int qt_metatype_id()
1579 Q_CONSTINIT static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0
);
1580 if (const int id = metatype_id.loadRelaxed())
1582 const char *tName = QMetaType::fromType<T>().name();
1584 const size_t tNameLen = qstrlen(tName);
1585 QByteArray typeName;
1586 typeName.reserve(sizeof(#SINGLE_ARG_TEMPLATE) + 1
+ tNameLen + 1
+ 1
);
1587 typeName.append(#SINGLE_ARG_TEMPLATE, int(sizeof(#SINGLE_ARG_TEMPLATE)) - 1
)
1588 .append('<').append(tName, tNameLen);
1589 typeName.append('>');
1590 const int newId = qRegisterNormalizedMetaType< SINGLE_ARG_TEMPLATE<T> >(typeName);
1591 metatype_id.storeRelease(newId);
1594};QT_END_NAMESPACE
1597#define Q_DECLARE_METATYPE_TEMPLATE_2ARG(DOUBLE_ARG_TEMPLATE) QT_BEGIN_NAMESPACE
1599 <typename T, typename U> struct
1600 QMetaTypeId< DOUBLE_ARG_TEMPLATE<T, U> > \
1601{
1603 Defined = QtPrivate::IsContainerElementWhichNeedsConverter<T>::value
1604 && QtPrivate::IsContainerElementWhichNeedsConverter<U>::value
1606 static int qt_metatype_id()
1608 Q_CONSTINIT static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0
);
1609 if (const int id = metatype_id.loadAcquire())
1611 const char *tName = QMetaType::fromType<T>().name();
1612 const char *uName = QMetaType::fromType<U>().name();
1615 const size_t tNameLen = qstrlen(tName);
1616 const size_t uNameLen = qstrlen(uName);
1617 QByteArray typeName;
1618 typeName.reserve(sizeof(#DOUBLE_ARG_TEMPLATE) + 1
+ tNameLen + 1
+ uNameLen + 1
+ 1
);
1619 typeName.append(#DOUBLE_ARG_TEMPLATE, int(sizeof(#DOUBLE_ARG_TEMPLATE)) - 1
)
1620 .append('<').append(tName, tNameLen).append(',').append(uName, uNameLen);
1621 typeName.append('>');
1622 const int newId = qRegisterNormalizedMetaType< DOUBLE_ARG_TEMPLATE<T, U> >(typeName);
1623 metatype_id.storeRelease(newId);
1626};QT_END_NAMESPACE
1631template<
typename T,
bool =
false>
1645#define Q_DECLARE_SMART_POINTER_METATYPE(SMART_POINTER) QT_BEGIN_NAMESPACE
1647 QtPrivate { template
1649 SharedPointerMetaTypeIdHelper<SMART_POINTER<T>, true> \
1650{
1654 static int qt_metatype_id()
1656 Q_CONSTINIT static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0
);
1657 if (const int id = metatype_id.loadAcquire())
1659 const char * const cName = T::staticMetaObject.className();
1660 QByteArray typeName;
1661 typeName.reserve(sizeof(#SMART_POINTER) + 1
+ strlen(cName) + 1
);
1662 typeName.append(#SMART_POINTER, int(sizeof(#SMART_POINTER)) - 1
)
1663 .append('<').append(cName).append('>');
1664 const int newId = qRegisterNormalizedMetaType< SMART_POINTER<T> >(typeName);
1665 metatype_id.storeRelease(newId);
1668};template
1670 MetaTypeSmartPointerHelper<SMART_POINTER<T> ,
1671 typename std::enable_if<IsPointerToTypeDerivedFromQObject<T*>::Value && !std::is_const_v<T>>::type> \
1672{
1673 static bool registerConverter()
1675 const QMetaType to = QMetaType(QMetaType::QObjectStar);
1676 if (!QMetaType::hasRegisteredConverterFunction(QMetaType::fromType<SMART_POINTER<T>>(), to)) {
1677 QtPrivate::QSmartPointerConvertFunctor<SMART_POINTER<T> > o;
1678 return QMetaType::registerConverter<SMART_POINTER<T>, QObject*>(o);
1682};\
1683}template
1685 QMetaTypeId< SMART_POINTER<T> >
1686 : QtPrivate::SharedPointerMetaTypeIdHelper< SMART_POINTER<T>,
1687 QtPrivate::IsPointerToTypeDerivedFromQObject<T*>::Value> \
1688{\
1689};QT_END_NAMESPACE
1692#define Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(SINGLE_ARG_TEMPLATE)
1694 namespace QtPrivate {
1695 template<typename T>
1696 struct IsSequentialContainer<SINGLE_ARG_TEMPLATE<T> >
1698 enum { Value = true };
1704#define Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE_ITER(TEMPLATENAME)
1711#undef Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE_ITER
1716#define Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE(TEMPLATENAME)
1718 namespace QtPrivate {
1719 template<typename T, typename U>
1720 struct IsAssociativeContainer<TEMPLATENAME<T, U> >
1722 enum { Value = true };
1734#define Q_DECLARE_METATYPE_TEMPLATE_SMART_POINTER_ITER(TEMPLATENAME)
1741#undef Q_DECLARE_METATYPE_TEMPLATE_SMART_POINTER_ITER
1759template <
typename T>
1764 return QMetaType::registerConverter<T, QtMetaTypePrivate::QPairVariantInterfaceImpl>(o);
1771template<
typename From>
1776 return QIterable<
QMetaSequence>(QMetaSequence::fromContainer<From>(), &f);
1780template<
typename From>
1785 return QIterable<
QMetaSequence>(QMetaSequence::fromContainer<From>(), &f);
1796 return QMetaType::registerConverter<T, QIterable<QMetaSequence>>(o);
1805 return QMetaType::registerMutableView<T, QIterable<QMetaSequence>>(o);
1811template<
typename From>
1816 return QIterable<
QMetaAssociation>(QMetaAssociation::fromContainer<From>(), &f);
1820template<
typename From>
1825 return QIterable<
QMetaAssociation>(QMetaAssociation::fromContainer<From>(), &f);
1838 return QMetaType::registerConverter<T, QIterable<QMetaAssociation>>(o);
1847 return QMetaType::registerMutableView<T, QIterable<QMetaAssociation>>(o);
1860 static constexpr bool is_ident_char(
char s)
1862 return ((s >=
'a' && s <=
'z') || (s >=
'A' && s <=
'Z') || (s >=
'0' && s <=
'9')
1865 static constexpr bool is_space(
char s) {
return (s ==
' ' || s ==
'\t' || s ==
'\n'); }
1866 static constexpr bool is_number(
char s) {
return s >=
'0' && s <=
'9'; }
1867 static constexpr bool starts_with_token(
const char *b,
const char *e,
const char *token,
1868 bool msvcKw =
false)
1870 while (b != e && *token && *b == *token) {
1879 if (msvcKw && !is_ident_char(*b))
1883 return b == e || !is_ident_char(*b);
1885 static constexpr bool skipToken(
const char *&x,
const char *e,
const char *token,
1886 bool msvcKw =
false)
1888 if (!starts_with_token(x, e, token, msvcKw))
1892 while (x != e && is_space(*x))
1896 static constexpr const char *skipString(
const char *x,
const char *e)
1900 while (x != e && *x != delim) {
1912 static constexpr const char *skipTemplate(
const char *x,
const char *e,
bool stopAtComa =
false)
1915 int templateDepth = 0;
1923 if (stopAtComa && !scopeDepth && !templateDepth)
1928 if (--templateDepth < 0)
1942 if (is_number(x[-1]))
1946 x = skipString(x, e);
1954 constexpr void append(
char x)
1962 constexpr void replaceLast(
char x)
1969 constexpr void appendStr(
const char *x)
1975 constexpr void normalizeIntegerTypes(
const char *&begin,
const char *end)
1979 int numUnsigned = 0;
1983 while (begin < end) {
1984 if (skipToken(begin, end,
"long")) {
1988 if (skipToken(begin, end,
"int")) {
1992 if (skipToken(begin, end,
"short")) {
1996 if (skipToken(begin, end,
"unsigned")) {
2000 if (skipToken(begin, end,
"signed")) {
2004 if (skipToken(begin, end,
"char")) {
2009 if (skipToken(begin, end,
"__int64")) {
2018 if (numSigned && numChar)
2019 appendStr(
"signed ");
2020 else if (numUnsigned)
2026 else if (numLong == 1)
2028 else if (numLong == 2)
2029 appendStr(
"longlong");
2030 else if (numUnsigned || numSigned || numInt)
2034 constexpr void skipStructClassOrEnum(
const char *&begin,
const char *end)
2038 skipToken(begin, end,
"struct",
true) || skipToken(begin, end,
"class",
true)
2039 || skipToken(begin, end,
"enum",
true);
2042 constexpr void skipQtNamespace(
const char *&begin,
const char *end)
2045 const char *nsbeg = begin;
2046 if (skipToken(nsbeg, end, QT_STRINGIFY(QT_NAMESPACE)) && nsbeg + 2 < end && nsbeg[0] ==
':'
2047 && nsbeg[1] ==
':') {
2049 while (begin != end && is_space(*begin))
2059#if defined(Q_CC_CLANG) || defined (Q_CC_GNU)
2067#if defined (Q_CC_CLANG)
2074 if (*
begin ==
' ') {
2112 constexpr int normalizeType(
const char *begin,
const char *end,
bool adjustConst =
true)
2115 while (begin != end && is_space(*begin))
2117 while (begin != end && is_space(*(end - 1)))
2125 const char *cst = begin + 1;
2126 if (*begin ==
'\'' || *begin ==
'"')
2127 cst = skipString(begin, end);
2128 bool seenStar =
false;
2129 bool hasMiddleConst =
false;
2131 if (*cst ==
'\"' || (*cst ==
'\'' && !is_number(cst[-1]))) {
2132 cst = skipString(cst, end);
2139 if (*cst ==
'&' || *cst ==
'*' || *cst ==
'[') {
2140 seenStar = *cst !=
'&' || cst != (end - 1);
2144 cst = skipTemplate(cst + 1, end);
2149 const char *skipedCst = cst;
2150 if (!is_ident_char(*(cst - 1)) && skipToken(skipedCst, end,
"const")) {
2151 const char *testEnd = end;
2152 while (skipedCst < testEnd--) {
2153 if (*testEnd ==
'*' || *testEnd ==
'['
2154 || (*testEnd ==
'&' && testEnd != (end - 1))) {
2158 if (*testEnd ==
'>')
2161 if (adjustConst && !seenStar) {
2162 if (*(end - 1) ==
'&')
2165 appendStr(
"const ");
2169 hasMiddleConst =
true;
2173 if (skipToken(begin, end,
"const")) {
2174 if (adjustConst && !seenStar) {
2175 if (*(end - 1) ==
'&')
2178 appendStr(
"const ");
2181 if (seenStar && adjustConst) {
2182 const char *e = end;
2183 if (*(end - 1) ==
'&' && *(end - 2) !=
'&')
2185 while (begin != e && is_space(*(e - 1)))
2187 const char *token =
"tsnoc";
2188 while (*token && begin != e && *(--e) == *token++)
2190 if (!*token && begin != e && !is_ident_char(*(e - 1))) {
2191 while (begin != e && is_space(*(e - 1)))
2197 skipStructClassOrEnum(begin, end);
2198 skipQtNamespace(begin, end);
2200 if (skipToken(begin, end,
"QVector")) {
2205 if (skipToken(begin, end,
"QPair")) {
2207 appendStr(
"std::pair");
2210 if (!hasMiddleConst)
2212 normalizeIntegerTypes(begin, end);
2214 bool spaceSkiped =
true;
2215 while (begin != end) {
2219 }
else if ((c ==
'\'' && !is_number(
last)) || c ==
'\"') {
2221 auto x = skipString(begin, end);
2225 if (spaceSkiped && is_ident_char(
last) && is_ident_char(c))
2228 spaceSkiped =
false;
2232 const char *tpl = skipTemplate(begin, end,
true);
2238 }
while (*begin++ ==
',');
2257template <
typename T1_,
typename T2_>
2270 std::remove_const_t<std::conditional_t<
bool (QMetaTypeId2<T1>::IsBuiltIn),
typename QMetaTypeId2<T1>::NameAsArrayType,
decltype(typenameHelper<T1>())>> t1Name {};
2271 std::remove_const_t<std::conditional_t<
bool (QMetaTypeId2<T2>::IsBuiltIn),
typename QMetaTypeId2<T2>::NameAsArrayType,
decltype(typenameHelper<T2>())>> t2Name {};
2275 t1Name = typenameHelper<T1>();
2280 t2Name = typenameHelper<T2>();
2282 constexpr auto nonTypeDependentLen =
sizeof(
"std::pair<,>");
2283 constexpr auto t1Len = t1Name.size() - 1;
2284 constexpr auto t2Len = t2Name.size() - 1;
2285 constexpr auto length = nonTypeDependentLen + t1Len + t2Len;
2286 std::array<
char, length + 1> result {};
2287 constexpr auto prefix =
"std::pair<";
2288 int currentLength = 0;
2289 for (; currentLength <
int(
sizeof(
"std::pair<") - 1); ++currentLength)
2290 result[currentLength] = prefix[currentLength];
2291 for (
int i = 0; i <
int(t1Len); ++currentLength, ++i)
2292 result[currentLength] = t1Name[i];
2293 result[currentLength++] =
',';
2294 for (
int i = 0; i <
int(t2Len); ++currentLength, ++i)
2295 result[currentLength] = t2Name[i];
2296 result[currentLength++] =
'>';
2297 result[currentLength++] =
'\0';
2300 constexpr auto prefix =
sizeof(
2302 QT_STRINGIFY(QT_NAMESPACE)
"::"
2304#if defined(Q_CC_MSVC) && defined(Q_CC_CLANG)
2305 "auto __cdecl QtPrivate::TypeNameHelper::typenameHelper(void) [T = "
2306#elif defined(Q_CC_MSVC)
2307 "auto __cdecl QtPrivate::TypeNameHelper::typenameHelper<"
2308#elif defined(Q_CC_CLANG)
2309 "auto QtPrivate::TypeNameHelper::typenameHelper() [T = "
2310#elif defined(Q_CC_GHS)
2311 "auto QtPrivate::TypeNameHelper::typenameHelper<T>()[with T="
2313 "constexpr auto QtPrivate::TypeNameHelper::typenameHelper() [with T = "
2316#if defined(Q_CC_MSVC) && !defined(Q_CC_CLANG)
2317 constexpr int suffix =
sizeof(
">(void)");
2319 constexpr int suffix =
sizeof(
"]");
2322#if defined(Q_CC_GNU_ONLY) && Q_CC_GNU_ONLY < 804
2323 auto func = Q_FUNC_INFO;
2324 const char *begin = func + prefix;
2325 const char *end = func +
sizeof(Q_FUNC_INFO) - suffix;
2327 constexpr int len =
sizeof(Q_FUNC_INFO) - suffix - prefix;
2329 constexpr auto func = Q_FUNC_INFO;
2330 constexpr const char *begin = func + prefix;
2331 constexpr const char *end = func +
sizeof(Q_FUNC_INFO) - suffix;
2334 std::array<
char, len + 1> result {};
2342template<
typename T,
typename =
void>
2356QT_WARNING_DISABLE_FLOAT_COMPARE
2358 {
return *
reinterpret_cast<
const T *>(
a) == *
reinterpret_cast<
const T *>(
b); }
2372 {
return *
reinterpret_cast<
const T *>(a) < *
reinterpret_cast<
const T *>(b); }
2387#ifndef QT_NO_DEBUG_STREAM
2392 { dbg << *
reinterpret_cast<
const T *>(a); }
2403#ifndef QT_NO_DATASTREAM
2408 { ds << *
reinterpret_cast<
const T *>(a); }
2410 { ds >> *
reinterpret_cast<T *>(a); }
2424#if !defined(Q_OS_WIN) && defined(Q_CC_CLANG)
2425# pragma GCC visibility push(hidden)
2434 template <
typename T>
2437#if !defined(QT_BOOTSTRAPPED)
2446 static constexpr decltype(typenameHelper<S>())
name = typenameHelper<S>();
2451 if constexpr (QTypeInfo<S>::isRelocatable)
2452 flags |= QMetaType::RelocatableType;
2453 if constexpr (!std::is_default_constructible_v<S> || !QTypeInfo<S>::isValueInitializationBitwiseZero)
2454 flags |= QMetaType::NeedsConstruction;
2455 if constexpr (!std::is_trivially_destructible_v<S>)
2456 flags |= QMetaType::NeedsDestruction;
2457 if constexpr (!std::is_trivially_copy_constructible_v<S>)
2458 flags |= QMetaType::NeedsCopyConstruction;
2459 if constexpr (!std::is_trivially_move_constructible_v<S>)
2460 flags |= QMetaType::NeedsMoveConstruction;
2461 if constexpr (IsPointerToTypeDerivedFromQObject<S>::Value)
2462 flags |= QMetaType::PointerToQObject;
2463 if constexpr (IsSharedPointerToTypeDerivedFromQObject<S>::Value)
2464 flags |= QMetaType::SharedPointerToQObject;
2465 if constexpr (IsWeakPointerToTypeDerivedFromQObject<S>::Value)
2466 flags |= QMetaType::WeakPointerToQObject;
2467 if constexpr (IsTrackingPointerToTypeDerivedFromQObject<S>::Value)
2468 flags |= QMetaType::TrackingPointerToQObject;
2469 if constexpr (IsEnumOrFlags<S>::value)
2470 flags |= QMetaType::IsEnumeration;
2471 if constexpr (IsGadgetHelper<S>::IsGadgetOrDerivedFrom)
2472 flags |= QMetaType::IsGadget;
2473 if constexpr (IsPointerToGadgetHelper<S>::IsGadgetOrDerivedFrom)
2474 flags |= QMetaType::PointerToGadget;
2475 if constexpr (std::is_pointer_v<S>)
2476 flags |= QMetaType::IsPointer;
2477 if constexpr (IsUnsignedEnum<S>)
2478 flags |= QMetaType::IsUnsignedEnumeration;
2479 if constexpr (IsQmlListType<S>)
2480 flags |= QMetaType::IsQmlList;
2481 if constexpr (std::is_const_v<std::remove_pointer_t<S>>)
2482 flags |= QMetaType::IsConst;
2488 if constexpr (std::is_default_constructible_v<S> && !QTypeInfo<S>::isValueInitializationBitwiseZero) {
2497 if constexpr (
std::is_copy_constructible_v<S> && !
std::is_trivially_copy_constructible_v<S>) {
2499 if constexpr (qxp::is_detected_v<QMetaTypeCopyTraits::HasDeprecatedCopyConstructorTest, S>) {
2500#if !defined(QT_BOOTSTRAPPED)
2503 QT_IGNORE_DEPRECATIONS(
new (addr) S(*
reinterpret_cast<
const S *>(other));)
2505 new (addr) S(*
reinterpret_cast<
const S *>(other));
2515 if constexpr (
std::is_move_constructible_v<S> && !
std::is_trivially_move_constructible_v<S>) {
2517 new (addr) S(
std::move(*
reinterpret_cast<S *>(other)));
2526 if constexpr (
std::is_destructible_v<S> && !
std::is_trivially_destructible_v<S>)
2528 reinterpret_cast<S *>(addr)->~S();
2585#if !defined(Q_OS_WIN) && defined(Q_CC_CLANG)
2586# pragma GCC visibility pop
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625#if !defined(QT_BOOTSTRAPPED) && !defined(Q_CC_MSVC) && !defined(Q_OS_INTEGRITY)
2627#ifdef QT_NO_DATA_RELOCATION
2628# define QT_METATYPE_DECLARE_EXTERN_TEMPLATE_ITER(TypeName, Id, Name)
2629 extern template class Q_CORE_EXPORT QMetaTypeForType<Name>;
2631# define QT_METATYPE_DECLARE_EXTERN_TEMPLATE_ITER(TypeName, Id, Name)
2632 extern template class Q_CORE_EXPORT QMetaTypeForType<Name>;
2633 extern template struct Q_CORE_EXPORT QMetaTypeInterfaceWrapper<Name>;
2641#undef QT_METATYPE_DECLARE_EXTERN_TEMPLATE_ITER
2650#define Q_REMOVE_POINTER_LIKE_IMPL(Pointer) template
2652 QRemovePointerLike<Pointer<T>> \
2653{
2655};
2658#undef Q_REMOVE_POINTER_LIKE_IMPL
2673template<
typename Unique,
typename T>
2679 if constexpr (
std::is_void_v<Tz>) {
2682 }
else if constexpr (
std::is_void_v<Unique>) {
2683 checkTypeIsSuitableForMetaType<Ty>();
2685 }
else if constexpr (
std::is_reference_v<Tz>) {
2687 }
else if constexpr (!
is_complete<Tz, Unique>::value) {
2698constexpr QMetaType QMetaType::fromType()
2700 QtPrivate::checkTypeIsSuitableForMetaType<T>();
2701 return QMetaType(QtPrivate::qMetaTypeInterfaceForType<T>());
2704template <
typename T>
bool
2705QMetaType::isSameTypeHelper(
const QtPrivate::QMetaTypeInterface *iface, std::true_type)
const noexcept
2708 constexpr int Id =
int(QMetaTypeId2<T>::MetaType);
2710#ifdef QT_NO_DATA_RELOCATION
2713 if constexpr (!std::is_void_v<T> && QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)) {
2717 if constexpr (Id <=
int(LastCoreType))
2718 return d_ptr == iface;
2730 return d_ptr->typeId.loadRelaxed() == Id;
2733template <
typename T>
bool
2734QMetaType::isSameTypeHelper(
const QtPrivate::QMetaTypeInterface *iface, std::false_type)
const
2740 return *
this == QMetaType(iface);
2743constexpr bool QMetaType::isValid(QT6_IMPL_NEW_OVERLOAD)
const noexcept
2748bool QMetaType::isRegistered(QT6_IMPL_NEW_OVERLOAD)
const noexcept
2750 return d_ptr && Q_LIKELY(d_ptr->typeId.loadRelaxed());
2753constexpr qsizetype QMetaType::sizeOf()
const
2755 return d_ptr ? d_ptr->size : 0;
2758constexpr qsizetype QMetaType::alignOf()
const
2760 return d_ptr ? d_ptr->alignment : 0;
2763constexpr QMetaType::TypeFlags QMetaType::flags()
const
2765 return d_ptr ? TypeFlags(d_ptr->flags) : TypeFlags{};
2768constexpr const QMetaObject *QMetaType::metaObject()
const
2770 return d_ptr && d_ptr->metaObjectFn ? d_ptr->metaObjectFn(d_ptr) :
nullptr;
2773constexpr const char *QMetaType::name()
const
2775 return d_ptr ? d_ptr->name :
nullptr;
2782 return qHash(type.id(), seed);
2788 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 PointerIsSuitableForMetaTypeHelper
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()
constexpr bool TypeIsSuitableForMetaType
constexpr bool TypeIsCompleteOrVoid
char qt_getEnumMetaObject(const T &)
static constexpr bool value
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