Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
\inmodule QtCore More...
#include <qmetatype.h>
Public Types | |
enum | Type { FirstCoreType = Bool , LastCoreType = Float16 , FirstGuiType = QFont , LastGuiType = QColorSpace , FirstWidgetsType = QSizePolicy , LastWidgetsType = QSizePolicy , HighestInternalId = LastWidgetsType , QReal = sizeof(qreal) == sizeof(double) ? Double : Float , UnknownType = 0 , User = 65536 } |
\macro Q_DECLARE_OPAQUE_POINTER(PointerType) More... | |
enum | TypeFlag { NeedsConstruction = 0x1 , NeedsDestruction = 0x2 , RelocatableType = 0x4 , PointerToQObject = 0x8 , IsEnumeration = 0x10 , SharedPointerToQObject = 0x20 , WeakPointerToQObject = 0x40 , TrackingPointerToQObject = 0x80 , IsUnsignedEnumeration = 0x100 , IsGadget = 0x200 , PointerToGadget = 0x400 , IsPointer = 0x800 , IsQmlList =0x1000 , IsConst = 0x2000 , NeedsCopyConstruction = 0x4000 , NeedsMoveConstruction = 0x8000 } |
The enum describes attributes of a type supported by QMetaType. More... | |
using | ConverterFunction = std::function<bool(const void *src, void *target)> |
using | MutableViewFunction = std::function<bool(void *src, void *target)> |
Public Member Functions | |
QMetaType (int type) | |
constexpr | QMetaType (const QtPrivate::QMetaTypeInterface *d) |
constexpr | QMetaType ()=default |
constexpr bool | isValid (QT6_DECL_NEW_OVERLOAD) const noexcept |
bool | isRegistered (QT6_DECL_NEW_OVERLOAD) const noexcept |
void | registerType () const |
int | id (int=0) const |
constexpr qsizetype | sizeOf () const |
constexpr qsizetype | alignOf () const |
constexpr TypeFlags | flags () const |
constexpr const QMetaObject * | metaObject () const |
constexpr const char * | name () const |
void * | create (const void *copy=nullptr) const |
void | destroy (void *data) const |
void * | construct (void *where, const void *copy=nullptr) const |
void | destruct (void *data) const |
QPartialOrdering | compare (const void *lhs, const void *rhs) const |
Compares the objects at lhs and rhs for ordering. | |
bool | equals (const void *lhs, const void *rhs) const |
Compares the objects at lhs and rhs for equality. | |
bool | isDefaultConstructible () const noexcept |
bool | isCopyConstructible () const noexcept |
bool | isMoveConstructible () const noexcept |
bool | isDestructible () const noexcept |
bool | isEqualityComparable () const |
Returns true if a less than or equality operator for the type described by this metatype was visible to the metatype declaration, otherwise false . | |
bool | isOrdered () const |
Returns true if a less than operator for the type described by this metatype was visible to the metatype declaration, otherwise false . | |
bool | save (QDataStream &stream, const void *data) const |
Writes the object pointed to by data to the given stream. | |
bool | load (QDataStream &stream, void *data) const |
Reads the object of this type from the given stream into data. | |
bool | hasRegisteredDataStreamOperators () const |
QMetaType | underlyingType () const |
bool | debugStream (QDebug &dbg, const void *rhs) |
Streams the object at rhs to the debug stream dbg. | |
bool | hasRegisteredDebugStreamOperator () const |
const QtPrivate::QMetaTypeInterface * | iface () const |
Static Public Member Functions | |
static void | registerNormalizedTypedef (const QT_PREPEND_NAMESPACE(QByteArray) &normalizedTypeName, QMetaType type) |
static bool | isRegistered (int type) |
Returns true if the datatype with ID type is registered; otherwise returns false . | |
template<typename T > | |
static constexpr QMetaType | fromType () |
static QMetaType | fromName (QByteArrayView name) |
Returns a QMetaType matching typeName. | |
template<typename From , typename To > | |
static bool | registerConverter () |
template<typename From , typename To > | |
static bool | registerConverter (To(From::*function)() const) |
template<typename From , typename To > | |
static bool | registerMutableView (To(From::*function)()) |
template<typename From , typename To > | |
static bool | registerConverter (To(From::*function)(bool *) const) |
template<typename From , typename To , typename UnaryFunction > | |
static bool | registerConverter (UnaryFunction function) |
template<typename From , typename To , typename UnaryFunction > | |
static bool | registerMutableView (UnaryFunction function) |
static bool | convert (QMetaType fromType, const void *from, QMetaType toType, void *to) |
Converts the object at from from fromType to the preallocated space at to typed toType. | |
static bool | canConvert (QMetaType fromType, QMetaType toType) |
Returns true if QMetaType::convert can convert from fromType to toType. | |
static bool | view (QMetaType fromType, void *from, QMetaType toType, void *to) |
Creates a mutable view on the object at from of fromType in the preallocated space at to typed toType. | |
static bool | canView (QMetaType fromType, QMetaType toType) |
Returns true if QMetaType::view can create a mutable view of type toType on type fromType. | |
template<typename From , typename To > | |
static bool | hasRegisteredConverterFunction () |
Returns true , if the meta type system has a registered conversion from type From to type To. | |
static bool | hasRegisteredConverterFunction (QMetaType fromType, QMetaType toType) |
Returns true , if the meta type system has a registered conversion from meta type id fromType to toType. | |
template<typename From , typename To > | |
static bool | hasRegisteredMutableViewFunction () |
Returns true , if the meta type system has a registered mutable view on type From of type To. | |
static bool | hasRegisteredMutableViewFunction (QMetaType fromType, QMetaType toType) |
Returns true , if the meta type system has a registered mutable view on meta type id fromType of meta type id toType. | |
static bool | registerConverterFunction (const ConverterFunction &f, QMetaType from, QMetaType to) |
Registers function f as converter function from type id from to to. | |
static void | unregisterConverterFunction (QMetaType from, QMetaType to) |
static bool | registerMutableViewFunction (const MutableViewFunction &f, QMetaType from, QMetaType to) |
Registers function f as mutable view of type id to on type id from. | |
static void | unregisterMutableViewFunction (QMetaType from, QMetaType to) |
static void | unregisterMetaType (QMetaType type) |
Friends | |
template<typename , bool > | |
struct | QtPrivate::SequentialValueTypeIsMetaType |
template<typename , bool > | |
struct | QtPrivate::AssociativeValueTypeIsMetaType |
template<typename , bool > | |
struct | QtPrivate::IsMetaTypePair |
template<typename , typename > | |
struct | QtPrivate::MetaTypeSmartPointerHelper |
class | QVariant |
bool | comparesEqual (const QMetaType &lhs, const QMetaType &rhs) |
Q_CORE_EXPORT QDebug | operator<< (QDebug d, QMetaType m) |
int | qRegisterMetaType (QMetaType meta) |
\threadsafe | |
Related Symbols | |
(Note that these are not member symbols.) | |
template< typename T > int | qRegisterMetaType (const char *typeName) |
\obsolete \threadsafe | |
template< typename T > int | qRegisterMetaType () |
\threadsafe | |
template< typename T > int | qMetaTypeId () |
\threadsafe | |
size_t | qHash (QMetaType type, size_t seed=0) |
\inmodule QtCore
The QMetaType class manages named types in the meta-object system.
\threadsafe \compares equality
The class is used as a helper to marshall types in QVariant and in queued signals and slots connections. It associates a type name to a type so that it can be created and destructed dynamically at run-time.
Type names can be registered with QMetaType by using either qRegisterMetaType() or registerType(). Registration is not required for most operations; it's only required for operations that attempt to resolve a type name in string form back to a QMetaType object or the type's ID. Those include some old-style signal-slot connections using QObject::connect(), reading user-types from \l QDataStream to \l QVariant, or binding to other languages and IPC mechanisms, like QML, D-Bus, JavaScript, etc.
The following code allocates and destructs an instance of {MyClass} by its name, which requires that
{MyClass} have been previously registered:
If we want the stream operators operator<<()
and operator>>()
to work on QVariant objects that store custom types, the custom type must provide operator<<()
and operator>>()
operators.
Definition at line 338 of file qmetatype.h.
using QMetaType::ConverterFunction = std::function<bool(const void *src, void *target)> |
Definition at line 557 of file qmetatype.h.
using QMetaType::MutableViewFunction = std::function<bool(void *src, void *target)> |
Definition at line 560 of file qmetatype.h.
enum QMetaType::Type |
\macro Q_DECLARE_OPAQUE_POINTER(PointerType)
This macro enables pointers to forward-declared types (PointerType) to be registered with QMetaType using either Q_DECLARE_METATYPE() or qRegisterMetaType().
\macro Q_DECLARE_METATYPE(Type)
This macro makes the type Type known to QMetaType as long as it provides a public default constructor, a public copy constructor and a public destructor. It is needed to use the type Type as a custom type in QVariant.
This macro requires that Type is a fully defined type at the point where it is used. For pointer types, it also requires that the pointed to type is fully defined. Use in conjunction with Q_DECLARE_OPAQUE_POINTER() to register pointers to forward declared types.
Ideally, this macro should be placed below the declaration of the class or struct. If that is not possible, it can be put in a private header file which has to be included every time that type is used in a QVariant.
Adding a Q_DECLARE_METATYPE() makes the type known to all template based functions, including QVariant. Note that if you intend to use the type in queued signal and slot connections or in QObject's property system, you also have to call qRegisterMetaType() since the names are resolved at runtime.
This example shows a typical use case of Q_DECLARE_METATYPE():
If MyStruct
is in a namespace, the Q_DECLARE_METATYPE() macro has to be outside the namespace:
Since {MyStruct} is now known to QMetaType, it can be used in QVariant:
Some types are registered automatically and do not need this macro:
\list
The stream operators should have the following signatures:
\macro Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(Container)
This macro makes the container Container known to QMetaType as a sequential container. This makes it possible to put an instance of Container<T> into a QVariant, if T itself is known to QMetaType.
Note that all of the Qt sequential containers already have built-in support, and it is not necessary to use this macro with them. The std::vector and std::list containers also have built-in support.
This example shows a typical use of Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE():
\macro Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE(Container)
This macro makes the container Container known to QMetaType as an associative container. This makes it possible to put an instance of Container<T, U> into a QVariant, if T and U are themselves known to QMetaType.
Note that all of the Qt associative containers already have built-in support, and it is not necessary to use this macro with them. The std::map container also has built-in support.
This example shows a typical use of Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE():
\macro Q_DECLARE_SMART_POINTER_METATYPE(SmartPointer)
This macro makes the smart pointer SmartPointer known to QMetaType as a smart pointer. This makes it possible to put an instance of SmartPointer<T> into a QVariant, if T is a type which inherits QObject.
Note that the QWeakPointer, QSharedPointer and QPointer already have built-in support, and it is not necessary to use this macro with them.
This example shows a typical use of Q_DECLARE_SMART_POINTER_METATYPE():
These are the built-in types supported by QMetaType:
\value Void void
\value Bool bool
\value Int int
\value UInt {unsigned int} \value Double
double
\value QChar QChar \value QString QString \value QByteArray QByteArray \value Nullptr {std::nullptr_t}
\value VoidStar {void *} \value Long
{long} \value LongLong LongLong \value Short
{short} \value Char
{char} \value Char16
{char16_t} \value Char32
{char32_t} \value ULong
{unsigned long} \value ULongLong ULongLong \value UShort
{unsigned short} \value SChar
{signed char} \value UChar
{unsigned char} \value Float
float
\value Float16 qfloat16 \omitvalue Float128 \omitvalue BFloat16 \omitvalue Int128 \omitvalue UInt128 \value QObjectStar QObject *
\value QCursor QCursor \value QDate QDate \value QSize QSize \value QTime QTime \value QVariantList QVariantList \value QPolygon QPolygon \value QPolygonF QPolygonF \value QColor QColor \value QColorSpace QColorSpace (introduced in Qt 5.15) \value QSizeF QSizeF \value QRectF QRectF \value QLine QLine \value QTextLength QTextLength \value QStringList QStringList \value QVariantMap QVariantMap \value QVariantHash QVariantHash \value QVariantPair QVariantPair \value QIcon QIcon \value QPen QPen \value QLineF QLineF \value QTextFormat QTextFormat \value QRect QRect \value QPoint QPoint \value QUrl QUrl \value QRegularExpression QRegularExpression \value QDateTime QDateTime \value QPointF QPointF \value QPalette QPalette \value QFont QFont \value QBrush QBrush \value QRegion QRegion \value QBitArray QBitArray \value QImage QImage \value QKeySequence QKeySequence \value QSizePolicy QSizePolicy \value QPixmap QPixmap \value QLocale QLocale \value QBitmap QBitmap \value QTransform QTransform \value QMatrix4x4 QMatrix4x4 \value QVector2D QVector2D \value QVector3D QVector3D \value QVector4D QVector4D \value QQuaternion QQuaternion \value QEasingCurve QEasingCurve \value QJsonValue QJsonValue \value QJsonObject QJsonObject \value QJsonArray QJsonArray \value QJsonDocument QJsonDocument \value QCborValue QCborValue \value QCborArray QCborArray \value QCborMap QCborMap \value QCborSimpleType QCborSimpleType \value QModelIndex QModelIndex \value QPersistentModelIndex QPersistentModelIndex (introduced in Qt 5.5) \value QUuid QUuid \value QByteArrayList QByteArrayList \value QVariant QVariant
\value User Base value for user types \value UnknownType This is an invalid type id. It is returned from QMetaType for types that are not registered
Additional types can be registered using qRegisterMetaType() or by calling registerType().
Enumerator | |
---|---|
FirstCoreType | |
LastCoreType | |
FirstGuiType | |
LastGuiType | |
FirstWidgetsType | |
LastWidgetsType | |
HighestInternalId | |
QReal | |
UnknownType | |
User |
Definition at line 342 of file qmetatype.h.
enum QMetaType::TypeFlag |
The enum describes attributes of a type supported by QMetaType.
\value NeedsConstruction This type has a default constructor. If the flag is not set, instances can be safely initialized with memset to 0. \value NeedsCopyConstruction (since 6.5) This type has a non-trivial copy constructor. If the flag is not set, instances can be copied with memcpy. \value NeedsMoveConstruction (since 6.5) This type has a non-trivial move constructor. If the flag is not set, instances can be moved with memcpy. \value NeedsDestruction This type has a non-trivial destructor. If the flag is not set, calls to the destructor are not necessary before discarding objects. \value RelocatableType An instance of a type having this attribute can be safely moved to a different memory location using memcpy. \omitvalue MovableType \omitvalue SharedPointerToQObject \value IsEnumeration This type is an enumeration. \value IsUnsignedEnumeration If the type is an Enumeration, its underlying type is unsigned. \value PointerToQObject This type is a pointer to a class derived from QObject. \value IsPointer This type is a pointer to another type. \omitvalue WeakPointerToQObject \omitvalue TrackingPointerToQObject \omitvalue IsGadget \omit (since Qt 5.5) This type is a Q_GADGET and its corresponding QMetaObject can be accessed with QMetaType::metaObject. \endomit \omitvalue PointerToGadget \omitvalue IsQmlList \value IsConst Indicates that values of this type are immutable; for instance, because they are pointers to const objects.
Note that the Needs flags may be set but the meta type may not have a publicly-accessible constructor of the relevant type or a publicly-accessible destructor.
Definition at line 396 of file qmetatype.h.
|
explicit |
Constructs a QMetaType object that contains all information about type typeId.
Definition at line 3275 of file qmetatype.cpp.
|
inlineexplicitconstexpr |
Definition at line 457 of file qmetatype.h.
|
constexprdefault |
Constructs a default, invalid, QMetaType object.
|
constexpr |
Returns the alignment of the type in bytes (i.e. alignof(T), where T is the actual type for which this QMetaType instance was constructed for).
This function is typically used together with construct() to perform low-level management of the memory used by a type.
Definition at line 2685 of file qmetatype.h.
Returns true
if QMetaType::convert can convert from fromType to toType.
The following conversions are supported by Qt:
\table \header
Casting between primitive type (int, float, bool etc.) is supported.
Converting between pointers of types derived from QObject will also return true for this function if a qobject_cast from the type described by fromType to the type described by toType would succeed.
A cast from a sequential container will also return true for this function if the toType is QVariantList.
Similarly, a cast from an associative container will also return true for this function the toType is QVariantHash or QVariantMap.
Definition at line 2570 of file qmetatype.cpp.
Returns true
if QMetaType::view can create a mutable view of type toType on type fromType.
Converting between pointers of types derived from QObject will return true for this function if a qobject_cast from the type described by fromType to the type described by toType would succeed.
You can create a mutable view of type QSequentialIterable on any container registered with Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE().
Similarly you can create a mutable view of type QAssociativeIterable on any container registered with Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE().
Definition at line 2473 of file qmetatype.cpp.
QPartialOrdering QMetaType::compare | ( | const void * | lhs, |
const void * | rhs ) const |
Compares the objects at lhs and rhs for ordering.
Returns QPartialOrdering::Unordered if comparison is not supported or the values are unordered. Otherwise, returns QPartialOrdering::Less, QPartialOrdering::Equivalent or QPartialOrdering::Greater if lhs is less than, equivalent to or greater than rhs, respectively.
Both objects must be of the type described by this metatype. If either lhs or rhs is \nullptr, the values are unordered. Comparison is only supported if the type's less than operator was visible to the metatype declaration.
If the type's equality operator was also visible, values will only compare equal if the equality operator says they are. In the absence of an equality operator, when neither value is less than the other, values are considered equal; if equality is also available and two such values are not equal, they are considered unordered, just as NaN (not a number) values of a floating point type lie outside its ordering.
{compare() == 0} only agrees with equals() if the less than operator was visible.Compares the objects at lhs and rhs. Both objects need to be of type typeId. result is set to less than, equal to or greater than zero, if lhs is less than, equal to or greater than rhs. Returns true
, if the comparison succeeded, otherwise false
.
Compares the objects at lhs and rhs. Both objects need to be of type typeId. result is set to less than, equal to or greater than zero, if lhs is less than, equal to or greater than rhs. Returns true
, if the comparison succeeded, otherwise false
.
Definition at line 754 of file qmetatype.cpp.
Constructs a value of the type that this QMetaType instance was constructed for in the existing memory addressed by where, that is a copy of copy, and returns where. If copy is zero, the value is default constructed.
This is a low-level function for explicitly managing the memory used to store the type. Consider calling create() if you don't need this level of control (that is, use "new" rather than "placement new").
You must ensure that where points to a location where the new value can be stored and that where is suitably aligned. The type's size can be queried by calling sizeOf().
The rule of thumb for alignment is that a type is aligned to its natural boundary, which is the smallest power of 2 that is bigger than the type, unless that alignment is larger than the maximum useful alignment for the platform. For practical purposes, alignment larger than 2 * sizeof(void*) is only necessary for special hardware instructions (e.g., aligned SSE loads and stores on x86).
Constructs a value of the given type in the existing memory addressed by where, that is a copy of copy, and returns where. If copy is zero, the value is default constructed.
This is a low-level function for explicitly managing the memory used to store the type. Consider calling create() if you don't need this level of control (that is, use "new" rather than "placement new").
You must ensure that where points to a location that can store a value of type type, and that where is suitably aligned. The type's size can be queried by calling sizeOf().
The rule of thumb for alignment is that a type is aligned to its natural boundary, which is the smallest power of 2 that is bigger than the type, unless that alignment is larger than the maximum useful alignment for the platform. For practical purposes, alignment larger than 2 * sizeof(void*) is only necessary for special hardware instructions (e.g., aligned SSE loads and stores on x86).
Constructs a value of the given type in the existing memory addressed by where, that is a copy of copy, and returns where. If copy is zero, the value is default constructed.
This is a low-level function for explicitly managing the memory used to store the type. Consider calling create() if you don't need this level of control (that is, use "new" rather than "placement new").
You must ensure that where points to a location that can store a value of type type, and that where is suitably aligned. The type's size can be queried by calling sizeOf().
The rule of thumb for alignment is that a type is aligned to its natural boundary, which is the smallest power of 2 that is bigger than the type, unless that alignment is larger than the maximum useful alignment for the platform. For practical purposes, alignment larger than 2 * sizeof(void*) is only necessary for special hardware instructions (e.g., aligned SSE loads and stores on x86).
Definition at line 690 of file qmetatype.cpp.
|
static |
Converts the object at from from fromType to the preallocated space at to typed toType.
Converts the object at from from fromTypeId to the preallocated space at to typed toTypeId. Returns true
, if the conversion succeeded, otherwise false.
Both from and to have to be valid pointers.
Returns true
, if the conversion succeeded, otherwise false.
Both from and to have to be valid pointers.
Converts the object at from from fromTypeId to the preallocated space at to typed toTypeId. Returns true
, if the conversion succeeded, otherwise false.
Both from and to have to be valid pointers.
Definition at line 2363 of file qmetatype.cpp.
Returns a copy of copy, assuming it is of the type that this QMetaType instance was created for. If copy is \nullptr, creates a default constructed instance.
Returns a copy of copy, assuming it is of type type. If copy is zero, creates a default constructed instance.
Returns a copy of copy, assuming it is of type type. If copy is zero, creates a default constructed instance.
Definition at line 632 of file qmetatype.cpp.
Streams the object at rhs to the debug stream dbg.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns true
on success, otherwise false.
Definition at line 1858 of file qmetatype.cpp.
Destroys the data, assuming it is of the type that this QMetaType instance was created for.
Definition at line 656 of file qmetatype.cpp.
Destructs the value, located at data, assuming that it is of the type for which this QMetaType instance was constructed for.
Unlike destroy(), this function only invokes the type's destructor, it doesn't invoke the delete operator.
Destructs the value of the given type, located at where.
Unlike destroy(), this function only invokes the type's destructor, it doesn't invoke the delete operator.
Destructs the value of the given type, located at where.
Unlike destroy(), this function only invokes the type's destructor, it doesn't invoke the delete operator.
Definition at line 712 of file qmetatype.cpp.
Compares the objects at lhs and rhs for equality.
Both objects must be of the type described by this metatype. Can only compare the two objects if a less than or equality operator for the type was visible to the metatype declaration. Otherwise, the metatype never considers values equal. When an equality operator was visible to the metatype declaration, it is authoritative; otherwise, if less than is visible, when neither value is less than the other, the two are considered equal. If values are unordered (see compare() for details) they are not equal.
Returns true if the two objects compare equal, otherwise false.
Definition at line 790 of file qmetatype.cpp.
|
constexpr |
Returns flags of the type for which this QMetaType instance was constructed. To inspect specific type traits, prefer using one of the "is-" functions rather than the flags directly.
Definition at line 2690 of file qmetatype.h.
|
static |
Returns a QMetaType matching typeName.
The returned object is not valid if the typeName is not known to QMetaType
Definition at line 3041 of file qmetatype.cpp.
|
staticconstexpr |
Returns the QMetaType corresponding to the type in the template parameter.
Definition at line 2664 of file qmetatype.h.
|
inlinestatic |
Returns true
, if the meta type system has a registered conversion from type From to type To.
Definition at line 737 of file qmetatype.h.
Returns true
, if the meta type system has a registered conversion from meta type id fromType to toType.
Definition at line 2654 of file qmetatype.cpp.
bool QMetaType::hasRegisteredDataStreamOperators | ( | ) | const |
Returns true
, if the meta type system has registered data stream operators for this meta type.
Definition at line 2971 of file qmetatype.cpp.
bool QMetaType::hasRegisteredDebugStreamOperator | ( | ) | const |
Returns true
, if the meta type system has a registered debug stream operator for type T.
Returns true
, if the meta type system has a registered debug stream operator for type id typeId.
Returns true
, if the meta type system has a registered debug stream operator for this meta type.
Returns true
, if the meta type system has a registered debug stream operator for type T.
Returns true
, if the meta type system has a registered debug stream operator for type id typeId.
Definition at line 1900 of file qmetatype.cpp.
|
inlinestatic |
Returns true
, if the meta type system has a registered mutable view on type From of type To.
Definition at line 746 of file qmetatype.h.
Returns true
, if the meta type system has a registered mutable view on meta type id fromType of meta type id toType.
Definition at line 2701 of file qmetatype.cpp.
|
inline |
Returns id type held by this QMetatype instance.
Definition at line 476 of file qmetatype.h.
|
inline |
Definition at line 771 of file qmetatype.h.
|
inlinenoexcept |
Returns true if this type can be copy-constructed. If it can be, then construct() and create() can be used with a {copy} parameter that is not null.
Definition at line 495 of file qmetatype.h.
|
inlinenoexcept |
Returns true if this type can be default-constructed. If it can be, then construct() and create() can be used with a {copy} parameter that is null.
Definition at line 494 of file qmetatype.h.
|
inlinenoexcept |
Returns true if this type can be destroyed. If it can be, then destroy() and destruct() can be called.
Definition at line 497 of file qmetatype.h.
bool QMetaType::isEqualityComparable | ( | ) | const |
Returns true
if a less than or equality operator for the type described by this metatype was visible to the metatype declaration, otherwise false
.
Definition at line 874 of file qmetatype.cpp.
|
inlinenoexcept |
Returns true if this type can be move-constructed. QMetaType currently does not have an API to make use of this trait.
Definition at line 496 of file qmetatype.h.
bool QMetaType::isOrdered | ( | ) | const |
Returns true
if a less than operator for the type described by this metatype was visible to the metatype declaration, otherwise false
.
Definition at line 885 of file qmetatype.cpp.
|
static |
Returns true
if the datatype with ID type is registered; otherwise returns false
.
Definition at line 2821 of file qmetatype.cpp.
|
inlinenoexcept |
|
constexprnoexcept |
Returns true
if this QMetaType object contains valid information about a type, false otherwise.
Definition at line 2670 of file qmetatype.h.
bool QMetaType::load | ( | QDataStream & | stream, |
void * | data ) const |
Reads the object of this type from the given stream into data.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns true
if the object is loaded successfully; otherwise returns false
.
Normally, you should not need to call this function directly. Instead, use QVariant's operator>>()
, which relies on load() to stream custom types.
Definition at line 2941 of file qmetatype.cpp.
|
constexpr |
Returns a QMetaObject relative to this type.
If the type is a pointer type to a subclass of QObject, flags() contains QMetaType::PointerToQObject and this function returns the corresponding QMetaObject. This can be used in combination with QMetaObject::newInstance() to create QObjects of this type.
If the type is a Q_GADGET, flags() contains QMetaType::IsGadget. If the type is a pointer to a Q_GADGET, flags() contains QMetaType::PointerToGadget. In both cases, this function returns its QMetaObject. This can be used to retrieve QMetaMethod and QMetaProperty and use them on a pointer of this type for example, as given by QVariant::data().
If the type is an enumeration, flags() contains QMetaType::IsEnumeration. In this case, this function returns the QMetaObject of the enclosing object if the enum was registered as a Q_ENUM or \nullptr otherwise.
Definition at line 2695 of file qmetatype.h.
|
constexpr |
Returns the type name associated with this QMetaType, or a null pointer if no matching type was found. The returned pointer must not be deleted.
Definition at line 2712 of file qmetatype.h.
Referenced by testing.tools.encode_pdf_filter._PdfStream::RegisterByName().
|
inlinestatic |
true
if the registration succeeded, otherwise false.Definition at line 564 of file qmetatype.h.
|
inlinestatic |
true
if the registration succeeded, otherwise false.Definition at line 571 of file qmetatype.h.
|
inlinestatic |
true
if the registration succeeded, otherwise false.The ok
pointer can be used by the function to indicate whether the conversion succeeded.
Definition at line 607 of file qmetatype.h.
|
inlinestatic |
true
if the registration succeeded, otherwise false.function must take an instance of type From
and return an instance of To
. It can be a function pointer, a lambda or a functor object. Since Qt 6.5, the function can also return an instance of std::optional<To>
to be able to indicate failed conversions.
Definition at line 628 of file qmetatype.h.
|
static |
Registers function f as converter function from type id from to to.
If there's already a conversion registered, this does nothing but deleting f. Returns true
if the registration succeeded, otherwise false.
Definition at line 1775 of file qmetatype.cpp.
|
inlinestatic |
{To
From::function()} as mutable view of type {To}
on type {From}
in the meta type system. Returns true
if the registration succeeded, otherwise false
. Definition at line 589 of file qmetatype.h.
|
inlinestatic |
true
if the registration succeeded, otherwise false
. Definition at line 653 of file qmetatype.h.
|
static |
Registers function f as mutable view of type id to on type id from.
Returns true
if the registration succeeded, otherwise false
.
Definition at line 1808 of file qmetatype.cpp.
|
static |
Registers a user type for marshalling, as an alias of another type (typedef). Note that normalizedTypeName is not checked for conformance with Qt's normalized format, so it must already conform.
Definition at line 2787 of file qmetatype.cpp.
|
inline |
Registers this QMetaType with the type registry so it can be found by name, using QMetaType::fromName().
Definition at line 466 of file qmetatype.h.
bool QMetaType::save | ( | QDataStream & | stream, |
const void * | data ) const |
Writes the object pointed to by data to the given stream.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns true
if the object is saved successfully; otherwise returns false
.
Normally, you should not need to call this function directly. Instead, use QVariant's operator<<()
, which relies on save() to stream custom types.
Definition at line 2903 of file qmetatype.cpp.
|
constexpr |
Returns the size of the type in bytes (i.e. sizeof(T), where T is the actual type for which this QMetaType instance was constructed for).
This function is typically used together with construct() to perform low-level management of the memory used by a type.
Returns the size of the given type in bytes (i.e. sizeof(T), where T is the actual type identified by the type argument).
This function is typically used together with construct() to perform low-level management of the memory used by a type.
Returns the size of the given type in bytes (i.e. sizeof(T), where T is the actual type identified by the type argument).
This function is typically used together with construct() to perform low-level management of the memory used by a type.
Definition at line 2680 of file qmetatype.h.
QMetaType QMetaType::underlyingType | ( | ) | const |
If this metatype represents an enumeration, this method returns a metatype of a numeric class of the same signedness and size as the enums underlying type. If it represents a QFlags type, it returns QMetaType::Int. In all other cases an invalid QMetaType is returned.
Definition at line 2988 of file qmetatype.cpp.
Invoked automatically when a converter function object is destroyed.
Definition at line 1833 of file qmetatype.cpp.
Definition at line 894 of file qmetatype.cpp.
Definition at line 1821 of file qmetatype.cpp.
Creates a mutable view on the object at from of fromType in the preallocated space at to typed toType.
Returns true
if the conversion succeeded, otherwise false.
Definition at line 2431 of file qmetatype.cpp.
Definition at line 522 of file qmetatype.h.
Definition at line 1847 of file qmetatype.cpp.
|
related |
Returns the hash value for the type, using seed to seed the calculation.
Definition at line 2722 of file qmetatype.h.
|
related |
\threadsafe
Returns the meta type id of type T
at compile time. If the type was not declared with Q_DECLARE_METATYPE(), compilation will fail.
Typical usage:
QMetaType::type() returns the same ID as qMetaTypeId(), but does a lookup at runtime based on the name of the type. QMetaType::type() is a bit slower, but compilation succeeds if a type is not registered.
Definition at line 1382 of file qmetatype.h.
|
related |
\threadsafe
Call this function to register the type T
. Returns the meta type Id.
Example:
This function requires that {T} is a fully defined type at the point where the function is called. For pointer types, it also requires that the pointed to type is fully defined. Use Q_DECLARE_OPAQUE_POINTER() to be able to register pointers to forward declared types.
To use the type T
in QMetaType, QVariant, or with the QObject::property() API, registration is not necessary.
To use the type T
in queued signal and slot connections, {qRegisterMetaType<T>()} must be called before the first connection is established. That is typically done in the constructor of the class that uses
T
, or in the {main()} function.
After a type has been registered, it can be found by its name using QMetaType::fromName().
Definition at line 1395 of file qmetatype.h.
|
related |
\obsolete \threadsafe
Registers the type name typeName for the type {T}. Returns the internal ID used by QMetaType. Any class or struct that has a public default constructor, a public copy constructor and a public destructor can be registered.
This function requires that {T} is a fully defined type at the point where the function is called. For pointer types, it also requires that the pointed to type is fully defined. Use Q_DECLARE_OPAQUE_POINTER() to be able to register pointers to forward declared types.
After a type has been registered, you can create and destroy objects of that type dynamically at run-time.
This example registers the class {MyClass}:
This function is useful to register typedefs so they can be used by QMetaProperty, or in QueuedConnections
Definition at line 1371 of file qmetatype.h.
|
friend |
\threadsafe
Registers the meta type meta and returns its type Id.
This function requires that {T} is a fully defined type at the point where the function is called. For pointer types, it also requires that the pointed to type is fully defined. Use Q_DECLARE_OPAQUE_POINTER() to be able to register pointers to forward declared types.
To use the type T
in QMetaType, QVariant, or with the QObject::property() API, registration is not necessary.
To use the type T
in queued signal and slot connections, {qRegisterMetaType<T>()} must be called before the first connection is established. That is typically done in the constructor of the class that uses
T
, or in the {main()} function.
After a type has been registered, it can be found by its name using QMetaType::fromName().
Definition at line 1401 of file qmetatype.h.
|
friend |
Definition at line 756 of file qmetatype.h.
|
friend |
Definition at line 757 of file qmetatype.h.
|
friend |
Definition at line 758 of file qmetatype.h.
|
friend |
Definition at line 755 of file qmetatype.h.
|
friend |
Definition at line 795 of file qmetatype.h.