346 FirstCoreType = Bool,
347 LastCoreType = Float16,
348 FirstGuiType = QFont,
349 LastGuiType = QColorSpace,
350 FirstWidgetsType = QSizePolicy,
351 LastWidgetsType = QSizePolicy,
352 HighestInternalId = LastWidgetsType,
354 QReal =
sizeof(qreal) ==
sizeof(
double) ? Double : Float,
362 UnknownType = 0, Bool = 1, Int = 2, UInt = 3, LongLong = 4, ULongLong = 5,
363 Double = 6, Long = 32, Short = 33, Char = 34, ULong = 35, UShort = 36,
364 UChar = 37, Float = 38,
366 QChar = 7, QString = 10, QStringList = 11, QByteArray = 12,
367 QBitArray = 13, QDate = 14, QTime = 15, QDateTime = 16, QUrl = 17,
368 QLocale = 18, QRect = 19, QRectF = 20, QSize = 21, QSizeF = 22,
369 QLine = 23, QLineF = 24, QPoint = 25, QPointF = 26,
370 QEasingCurve = 29, QUuid = 30, QVariant = 41, QModelIndex = 42,
371 QPersistentModelIndex = 50, QRegularExpression = 44,
372 QJsonValue = 45, QJsonObject = 46, QJsonArray = 47, QJsonDocument = 48,
373 QByteArrayList = 49, QObjectStar = 39, SChar = 40,
376 QVariantMap = 8, QVariantList = 9, QVariantHash = 28, QVariantPair = 58,
377 QCborSimpleType = 52, QCborValue = 53, QCborArray = 54, QCborMap = 55,
378 Char16 = 56, Char32 = 57,
379 Int128 = 59, UInt128 = 60, Float128 = 61, BFloat16 = 62, Float16 = 63,
382 QFont = 0x1000, QPixmap = 0x1001, QBrush = 0x1002, QColor = 0x1003, QPalette = 0x1004,
383 QIcon = 0x1005, QImage = 0x1006, QPolygon = 0x1007, QRegion = 0x1008, QBitmap = 0x1009,
384 QCursor = 0x100a, QKeySequence = 0x100b, QPen = 0x100c, QTextLength = 0x100d, QTextFormat = 0x100e,
385 QTransform = 0x1010, QMatrix4x4 = 0x1011, QVector2D = 0x1012,
386 QVector3D = 0x1013, QVector4D = 0x1014, QQuaternion = 0x1015, QPolygonF = 0x1016, QColorSpace = 0x1017,
389 QSizePolicy = 0x2000,
397 NeedsConstruction = 0x1,
398 NeedsDestruction = 0x2,
399 RelocatableType = 0x4,
400#if QT_DEPRECATED_SINCE(6
, 0
)
401 MovableType Q_DECL_ENUMERATOR_DEPRECATED_X(
"Use RelocatableType instead.") = RelocatableType,
403 PointerToQObject = 0x8,
404 IsEnumeration = 0x10,
405 SharedPointerToQObject = 0x20,
406 WeakPointerToQObject = 0x40,
407 TrackingPointerToQObject = 0x80,
408 IsUnsignedEnumeration = 0x100,
410 PointerToGadget = 0x400,
415 NeedsCopyConstruction = 0x4000,
416 NeedsMoveConstruction = 0x8000,
418 Q_DECLARE_FLAGS(TypeFlags, TypeFlag)
420 static void registerNormalizedTypedef(
const QT_PREPEND_NAMESPACE(QByteArray) &normalizedTypeName, QMetaType type);
422#if QT_DEPRECATED_SINCE(6
, 0
)
423 QT_DEPRECATED_VERSION_6_0
424 static int type(
const char *typeName)
425 {
return QMetaType::fromName(typeName).id(); }
426 QT_DEPRECATED_VERSION_6_0
427 static int type(
const QT_PREPEND_NAMESPACE(QByteArray) &typeName)
428 {
return QMetaType::fromName(typeName).id(); }
429 QT_DEPRECATED_VERSION_6_0
430 static const char *typeName(
int type)
431 {
return QMetaType(type).name(); }
432 QT_DEPRECATED_VERSION_6_0
433 static int sizeOf(
int type)
434 {
return int(QMetaType(type).sizeOf()); }
435 QT_DEPRECATED_VERSION_6_0
436 static TypeFlags typeFlags(
int type)
437 {
return QMetaType(type).flags(); }
438 QT_DEPRECATED_VERSION_6_0
439 static const QMetaObject *metaObjectForType(
int type)
440 {
return QMetaType(type).metaObject(); }
441 QT_DEPRECATED_VERSION_6_0
442 static void *create(
int type,
const void *copy =
nullptr)
443 {
return QMetaType(type).create(copy); }
444 QT_DEPRECATED_VERSION_6_0
445 static void destroy(
int type,
void *data)
446 {
return QMetaType(type).destroy(data); }
447 QT_DEPRECATED_VERSION_6_0
448 static void *construct(
int type,
void *where,
const void *copy)
449 {
return QMetaType(type).construct(where, copy); }
450 QT_DEPRECATED_VERSION_6_0
451 static void destruct(
int type,
void *where)
452 {
return QMetaType(type).destruct(where); }
454 static bool isRegistered(
int type);
456 explicit QMetaType(
int type);
457 explicit constexpr QMetaType(
const QtPrivate::QMetaTypeInterface *d) : d_ptr(d) {}
458 constexpr QMetaType() =
default;
460#if QT_CORE_REMOVED_SINCE(6
, 9
)
461 bool isValid()
const;
462 bool isRegistered()
const;
464 constexpr bool isValid(QT6_DECL_NEW_OVERLOAD)
const noexcept;
465 inline bool isRegistered(QT6_DECL_NEW_OVERLOAD)
const noexcept;
466 void registerType()
const
471#if QT_CORE_REMOVED_SINCE(6
, 1
) || defined(Q_QDOC)
476 int id(
int = 0)
const
478 return registerHelper();
481 constexpr qsizetype sizeOf()
const;
482 constexpr qsizetype alignOf()
const;
483 constexpr TypeFlags flags()
const;
484 constexpr const QMetaObject *metaObject()
const;
485 constexpr const char *name()
const;
487 void *create(
const void *copy =
nullptr)
const;
488 void destroy(
void *data)
const;
489 void *construct(
void *where,
const void *copy =
nullptr)
const;
490 void destruct(
void *data)
const;
491 QPartialOrdering compare(
const void *lhs,
const void *rhs)
const;
492 bool equals(
const void *lhs,
const void *rhs)
const;
494 bool isDefaultConstructible()
const noexcept {
return d_ptr && isDefaultConstructible(d_ptr); }
495 bool isCopyConstructible()
const noexcept {
return d_ptr && isCopyConstructible(d_ptr); }
496 bool isMoveConstructible()
const noexcept {
return d_ptr && isMoveConstructible(d_ptr); }
497 bool isDestructible()
const noexcept {
return d_ptr && isDestructible(d_ptr); }
498 bool isEqualityComparable()
const;
499 bool isOrdered()
const;
501#ifndef QT_NO_DATASTREAM
502 bool save(QDataStream &stream,
const void *data)
const;
503 bool load(QDataStream &stream,
void *data)
const;
504 bool hasRegisteredDataStreamOperators()
const;
506#if QT_DEPRECATED_SINCE(6
, 0
)
507 QT_DEPRECATED_VERSION_6_0
508 static bool save(QDataStream &stream,
int type,
const void *data)
509 {
return QMetaType(type).save(stream, data); }
510 QT_DEPRECATED_VERSION_6_0
511 static bool load(QDataStream &stream,
int type,
void *data)
512 {
return QMetaType(type).load(stream, data); }
516 QMetaType underlyingType()
const;
519 constexpr static QMetaType fromType();
520 static QMetaType fromName(QByteArrayView name);
522 friend bool comparesEqual(
const QMetaType &lhs,
523 const QMetaType &rhs)
525 if (lhs.d_ptr == rhs.d_ptr)
527 if (!lhs.d_ptr || !rhs.d_ptr)
530 const int aId = lhs.id();
531 const int bId = rhs.id();
534 Q_DECLARE_EQUALITY_COMPARABLE_NON_NOEXCEPT(QMetaType)
535#ifndef QT_NO_DEBUG_STREAM
537 friend Q_CORE_EXPORT QDebug operator<<(QDebug d, QMetaType m);
539 bool debugStream(QDebug& dbg,
const void *rhs);
540 bool hasRegisteredDebugStreamOperator()
const;
542#if QT_DEPRECATED_SINCE(6
, 0
)
543 QT_DEPRECATED_VERSION_6_0
544 static bool debugStream(QDebug& dbg,
const void *rhs,
int typeId)
545 {
return QMetaType(typeId).debugStream(dbg, rhs); }
547 QT_DEPRECATED_VERSION_6_0
548 static bool hasRegisteredDebugStreamOperator()
549 {
return QMetaType::fromType<T>().hasRegisteredDebugStreamOperator(); }
550 QT_DEPRECATED_VERSION_6_0
551 static bool hasRegisteredDebugStreamOperator(
int typeId)
552 {
return QMetaType(typeId).hasRegisteredDebugStreamOperator(); }
557 using ConverterFunction = std::function<
bool(
const void *src,
void *target)>;
560 using MutableViewFunction = std::function<
bool(
void *src,
void *target)>;
563 template<
typename From,
typename To>
564 static bool registerConverter()
566 return registerConverter<From, To>(QtPrivate::convertImplicit<From, To>);
570 template<
typename From,
typename To>
571 static bool registerConverter(To(From::*function)()
const)
573 static_assert((!QMetaTypeId2<To>::IsBuiltIn || !QMetaTypeId2<From>::IsBuiltIn),
574 "QMetaType::registerConverter: At least one of the types must be a custom type.");
576 const QMetaType fromType = QMetaType::fromType<From>();
577 const QMetaType toType = QMetaType::fromType<To>();
578 auto converter = [function](
const void *from,
void *to) ->
bool {
579 const From *f =
static_cast<
const From *>(from);
580 To *t =
static_cast<To *>(to);
581 *t = (f->*function)();
584 return registerConverterImpl<From, To>(converter, fromType, toType);
588 template<
typename From,
typename To>
589 static bool registerMutableView(To(From::*function)())
591 static_assert((!QMetaTypeId2<To>::IsBuiltIn || !QMetaTypeId2<From>::IsBuiltIn),
592 "QMetaType::registerMutableView: At least one of the types must be a custom type.");
594 const QMetaType fromType = QMetaType::fromType<From>();
595 const QMetaType toType = QMetaType::fromType<To>();
596 auto view = [function](
void *from,
void *to) ->
bool {
597 From *f =
static_cast<From *>(from);
598 To *t =
static_cast<To *>(to);
599 *t = (f->*function)();
602 return registerMutableViewImpl<From, To>(view, fromType, toType);
606 template<
typename From,
typename To>
607 static bool registerConverter(To(From::*function)(
bool*)
const)
609 static_assert((!QMetaTypeId2<To>::IsBuiltIn || !QMetaTypeId2<From>::IsBuiltIn),
610 "QMetaType::registerConverter: At least one of the types must be a custom type.");
612 const QMetaType fromType = QMetaType::fromType<From>();
613 const QMetaType toType = QMetaType::fromType<To>();
614 auto converter = [function](
const void *from,
void *to) ->
bool {
615 const From *f =
static_cast<
const From *>(from);
616 To *t =
static_cast<To *>(to);
618 *t = (f->*function)(&result);
623 return registerConverterImpl<From, To>(converter, fromType, toType);
627 template<
typename From,
typename To,
typename UnaryFunction>
628 static bool registerConverter(UnaryFunction function)
630 static_assert((!QMetaTypeId2<To>::IsBuiltIn || !QMetaTypeId2<From>::IsBuiltIn),
631 "QMetaType::registerConverter: At least one of the types must be a custom type.");
633 const QMetaType fromType = QMetaType::fromType<From>();
634 const QMetaType toType = QMetaType::fromType<To>();
635 auto converter = [function = std::move(function)](
const void *from,
void *to) ->
bool {
636 const From *f =
static_cast<
const From *>(from);
637 To *t =
static_cast<To *>(to);
638 auto &&r = function(*f);
639 if constexpr (std::is_same_v<q20::remove_cvref_t<
decltype(r)>, std::optional<To>>) {
642 *t = *std::forward<
decltype(r)>(r);
644 *t = std::forward<
decltype(r)>(r);
648 return registerConverterImpl<From, To>(std::move(converter), fromType, toType);
652 template<
typename From,
typename To,
typename UnaryFunction>
653 static bool registerMutableView(UnaryFunction function)
655 static_assert((!QMetaTypeId2<To>::IsBuiltIn || !QMetaTypeId2<From>::IsBuiltIn),
656 "QMetaType::registerMutableView: At least one of the types must be a custom type.");
658 const QMetaType fromType = QMetaType::fromType<From>();
659 const QMetaType toType = QMetaType::fromType<To>();
660 auto view = [function = std::move(function)](
void *from,
void *to) ->
bool {
661 From *f =
static_cast<From *>(from);
662 To *t =
static_cast<To *>(to);
666 return registerMutableViewImpl<From, To>(std::move(view), fromType, toType);
670 template<
typename From,
typename To>
671 static bool registerConverterImpl(ConverterFunction converter, QMetaType fromType, QMetaType toType)
673 if (registerConverterFunction(std::move(converter), fromType, toType)) {
674 static const auto unregister = qScopeGuard([=] {
675 unregisterConverterFunction(fromType, toType);
683 template<
typename From,
typename To>
684 static bool registerMutableViewImpl(MutableViewFunction view, QMetaType fromType, QMetaType toType)
686 if (registerMutableViewFunction(std::move(view), fromType, toType)) {
687 static const auto unregister = qScopeGuard([=] {
688 unregisterMutableViewFunction(fromType, toType);
697 static bool convert(QMetaType fromType,
const void *from, QMetaType toType,
void *to);
698 static bool canConvert(QMetaType fromType, QMetaType toType);
700 static bool view(QMetaType fromType,
void *from, QMetaType toType,
void *to);
701 static bool canView(QMetaType fromType, QMetaType toType);
702#if QT_DEPRECATED_SINCE(6
, 0
)
703 QT_DEPRECATED_VERSION_6_0
704 static bool convert(
const void *from,
int fromTypeId,
void *to,
int toTypeId)
705 {
return convert(QMetaType(fromTypeId), from, QMetaType(toTypeId), to); }
706 QT_DEPRECATED_VERSION_6_0
707 static bool compare(
const void *lhs,
const void *rhs,
int typeId,
int *result)
710 auto c = t.compare(lhs, rhs);
711 if (c == QPartialOrdering::Unordered) {
714 }
else if (c == QPartialOrdering::Less) {
717 }
else if (c == QPartialOrdering::Equivalent) {
725 QT_DEPRECATED_VERSION_6_0
726 static bool equals(
const void *lhs,
const void *rhs,
int typeId,
int *result)
729 if (!t.isEqualityComparable())
731 *result = t.equals(lhs, rhs) ? 0 : -1;
736 template<
typename From,
typename To>
737 static bool hasRegisteredConverterFunction()
739 return hasRegisteredConverterFunction(
740 QMetaType::fromType<From>(), QMetaType::fromType<To>());
743 static bool hasRegisteredConverterFunction(QMetaType fromType, QMetaType toType);
745 template<
typename From,
typename To>
746 static bool hasRegisteredMutableViewFunction()
748 return hasRegisteredMutableViewFunction(
749 QMetaType::fromType<From>(), QMetaType::fromType<To>());
752 static bool hasRegisteredMutableViewFunction(QMetaType fromType, QMetaType toType);
755 template<
typename,
bool>
friend struct QtPrivate::SequentialValueTypeIsMetaType;
756 template<
typename,
bool>
friend struct QtPrivate::AssociativeValueTypeIsMetaType;
757 template<
typename,
bool>
friend struct QtPrivate::IsMetaTypePair;
758 template<
typename,
typename>
friend struct QtPrivate::MetaTypeSmartPointerHelper;
760 static bool registerConverterFunction(
const ConverterFunction &f, QMetaType from, QMetaType to);
761 static void unregisterConverterFunction(QMetaType from, QMetaType to);
763 static bool registerMutableViewFunction(
const MutableViewFunction &f, QMetaType from, QMetaType to);
764 static void unregisterMutableViewFunction(QMetaType from, QMetaType to);
766 static void unregisterMetaType(QMetaType type);
768#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
769 const QtPrivate::QMetaTypeInterface *iface() {
return d_ptr; }
771 const QtPrivate::QMetaTypeInterface *iface()
const {
return d_ptr; }
774 static bool isDefaultConstructible(
const QtPrivate::QMetaTypeInterface *)
noexcept Q_DECL_PURE_FUNCTION;
775 static bool isCopyConstructible(
const QtPrivate::QMetaTypeInterface *)
noexcept Q_DECL_PURE_FUNCTION;
776 static bool isMoveConstructible(
const QtPrivate::QMetaTypeInterface *)
noexcept Q_DECL_PURE_FUNCTION;
777 static bool isDestructible(
const QtPrivate::QMetaTypeInterface *)
noexcept Q_DECL_PURE_FUNCTION;
779#if QT_CORE_REMOVED_SINCE(6
, 5
)
780 int idHelper()
const;
782 static int registerHelper(
const QtPrivate::QMetaTypeInterface *iface);
783 int registerHelper()
const
786 if (
int id = d_ptr->typeId.loadRelaxed())
788 return registerHelper(d_ptr);
793 friend int qRegisterMetaType(QMetaType meta);
795 friend class QVariant;
796 const QtPrivate::QMetaTypeInterface *d_ptr =
nullptr;