QtBase  v6.3.1
Public Types | Public Member Functions | Static Public Member Functions | Friends | Related Functions | List of all members
QMetaType Class Reference

The QMetaType class manages named types in the meta-object system. More...

#include <qmetatype.h>

Public Types

enum  Type {
  FirstCoreType = Bool , LastCoreType = QVariantPair , FirstGuiType = QFont , LastGuiType = QColorSpace ,
  FirstWidgetsType = QSizePolicy , LastWidgetsType = QSizePolicy , HighestInternalId = LastWidgetsType , QReal = sizeof(qreal) == sizeof(double) ? Double : Float ,
  UnknownType = 0 , User = 65536
}
 
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
}
 
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
 
bool isValid () const
 
bool isRegistered () const
 
int id (int=0) const
 
constexpr qsizetype sizeOf () const
 
constexpr qsizetype alignOf () const
 
constexpr TypeFlags flags () const
 
constexpr const QMetaObjectmetaObject () const
 
constexpr const char * name () const
 
voidcreate (const void *copy=nullptr) const
 
void destroy (void *data) const
 
voidconstruct (void *where, const void *copy=nullptr) const
 
void destruct (void *data) const
 
QPartialOrdering compare (const void *lhs, const void *rhs) const
 
bool equals (const void *lhs, const void *rhs) const
 
bool isEqualityComparable () const
 
bool isOrdered () const
 
bool save (QDataStream &stream, const void *data) const
 
bool load (QDataStream &stream, void *data) const
 
bool hasRegisteredDataStreamOperators () const
 
bool debugStream (QDebug &dbg, const void *rhs)
 
bool hasRegisteredDebugStreamOperator () const
 
const QtPrivate::QMetaTypeInterfaceiface () const
 
template<typename T >
constexpr QMetaType fromType ()
 

Static Public Member Functions

static void registerNormalizedTypedef (const QT_PREPEND_NAMESPACE(QByteArray) &normalizedTypeName, QMetaType type)
 
static bool isRegistered (int type)
 
template<typename T >
constexpr static QMetaType fromType ()
 
static QMetaType fromName (QByteArrayView name)
 
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)
 
static bool canConvert (QMetaType fromType, QMetaType toType)
 
static bool view (QMetaType fromType, void *from, QMetaType toType, void *to)
 
static bool canView (QMetaType fromType, QMetaType toType)
 
template<typename From , typename To >
static bool hasRegisteredConverterFunction ()
 
static bool hasRegisteredConverterFunction (QMetaType fromType, QMetaType toType)
 
template<typename From , typename To >
static bool hasRegisteredMutableViewFunction ()
 
static bool hasRegisteredMutableViewFunction (QMetaType fromType, QMetaType toType)
 
static bool registerConverterFunction (const ConverterFunction &f, QMetaType from, QMetaType to)
 
static void unregisterConverterFunction (QMetaType from, QMetaType to)
 
static bool registerMutableViewFunction (const MutableViewFunction &f, QMetaType from, QMetaType to)
 
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 operator== (QMetaType a, QMetaType b)
 
bool operator!= (QMetaType a, QMetaType b)
 

Related Functions

(Note that these are not member functions.)

int qRegisterMetaType (const char *typeName)
 
int qRegisterMetaType ()
 
int qMetaTypeId ()
 

Detailed Description

The QMetaType class manages named types in the meta-object system.

\inmodule QtCore

\threadsafe

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. Declare new types with Q_DECLARE_METATYPE() to make them available to QVariant and other template-based functions. Call qRegisterMetaType() to make types available to non-template based functions, such as the queued signal and slot connections.

Any class or struct that has a public default constructor, a public copy constructor, and a public destructor can be registered.

The following code allocates and destructs an instance of {MyClass}:

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.

See also
Q_DECLARE_METATYPE(), QVariant::setValue(), QVariant::value(), QVariant::fromValue()

Definition at line 328 of file qmetatype.h.

Member Typedef Documentation

◆ ConverterFunction

Definition at line 533 of file qmetatype.h.

◆ MutableViewFunction

Definition at line 536 of file qmetatype.h.

Member Enumeration Documentation

◆ Type

\macro Q_DECLARE_OPAQUE_POINTER(PointerType)

Since
5.0

This macro enables pointers to forward-declared types (PointerType) to be registered with QMetaType using either Q_DECLARE_METATYPE() or qRegisterMetaType().

See also
Q_DECLARE_METATYPE(), 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

  • Pointers to classes derived from QObject
  • QList<T>, QQueue<T>, QStack<T> or QSet<T> where T is a registered meta type
  • QHash<T1, T2>, QMap<T1, T2> or QPair<T1, T2> where T1 and T2 are registered meta types
  • QPointer<T>, QSharedPointer<T>, QWeakPointer<T>, where T is a class that derives from QObject
  • Enumerations registered with Q_ENUM or Q_FLAG
  • Classes that have a Q_GADGET macro \endlist
Note
This method also registers the stream and debug operators for the type if they are visible at registration time. As this is done automatically in some places, it is strongly recommended to declare the stream operators for a type directly after the type itself. Because of the argument dependent lookup rules of C++, it is also strongly recommended to declare the operators in the same namespace as the type itself.

The stream operators should have the following signatures:

See also
qRegisterMetaType()

\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 QObjectStar QObject * \value QVariant QVariant

\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 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 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 \omitvalue LastCoreType \omitvalue LastGuiType

Additional types can be registered using Q_DECLARE_METATYPE().

See also
type(), typeName()
Enumerator
FirstCoreType 
LastCoreType 
FirstGuiType 
LastGuiType 
FirstWidgetsType 
LastWidgetsType 
HighestInternalId 
QReal 
UnknownType 
User 

Definition at line 332 of file qmetatype.h.

◆ TypeFlag

The enum describes attributes of a type supported by QMetaType.

\value NeedsConstruction This type has non-trivial constructors. If the flag is not set instances can be safely initialized with memset to 0. \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 derived of QObject. \value IsPointer This type is a pointer to another type. \omitvalue WeakPointerToQObject \omitvalue TrackingPointerToQObject \omitvalue IsGadget \omit This type is a Q_GADGET and it's corresponding QMetaObject can be accessed with QMetaType::metaObject Since 5.5. \endomit \omitvalue PointerToGadget \omitvalue IsQmlList \value IsConst Indicates that values of this types are immutable; for instance because they are pointers to const objects.

Enumerator
NeedsConstruction 
NeedsDestruction 
RelocatableType 
PointerToQObject 
IsEnumeration 
SharedPointerToQObject 
WeakPointerToQObject 
TrackingPointerToQObject 
IsUnsignedEnumeration 
IsGadget 
PointerToGadget 
IsPointer 
IsQmlList 
IsConst 

Definition at line 385 of file qmetatype.h.

Constructor & Destructor Documentation

◆ QMetaType() [1/3]

QMetaType::QMetaType ( int  typeId)
explicit
Since
5.0

Constructs a QMetaType object that contains all information about type typeId.

Definition at line 3001 of file qmetatype.cpp.

◆ QMetaType() [2/3]

constexpr QMetaType::QMetaType ( const QtPrivate::QMetaTypeInterface d)
inlineexplicitconstexpr

Definition at line 443 of file qmetatype.h.

◆ QMetaType() [3/3]

constexpr QMetaType::QMetaType ( )
constexprdefault
Here is the caller graph for this function:

Member Function Documentation

◆ alignOf()

constexpr qsizetype QMetaType::alignOf ( ) const
constexpr
Since
6.0

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.

See also
QMetaType::construct(), QMetaType::sizeOf()

Definition at line 2511 of file qmetatype.h.

◆ canConvert()

bool QMetaType::canConvert ( QMetaType  fromType,
QMetaType  toType 
)
static

Returns true if QMetaType::convert can convert from fromType to toType.

The following conversions are supported by Qt:

\table \header

  • Type
  • Automatically Cast To \row
  • \l QMetaType::Bool
  • \l QMetaType::QChar, \l QMetaType::Double, \l QMetaType::Int, \l QMetaType::LongLong, \l QMetaType::QString, \l QMetaType::UInt, \l QMetaType::ULongLong \row
  • \l QMetaType::QByteArray
  • \l QMetaType::Double, \l QMetaType::Int, \l QMetaType::LongLong, \l QMetaType::QString, \l QMetaType::UInt, \l QMetaType::ULongLong, \l QMetaType::QUuid \row
  • \l QMetaType::QChar
  • \l QMetaType::Bool, \l QMetaType::Int, \l QMetaType::UInt, \l QMetaType::LongLong, \l QMetaType::ULongLong \row
  • \l QMetaType::QColor
  • \l QMetaType::QString \row
  • \l QMetaType::QDate
  • \l QMetaType::QDateTime, \l QMetaType::QString \row
  • \l QMetaType::QDateTime
  • \l QMetaType::QDate, \l QMetaType::QString, \l QMetaType::QTime \row
  • \l QMetaType::Double
  • \l QMetaType::Bool, \l QMetaType::Int, \l QMetaType::LongLong, \l QMetaType::QString, \l QMetaType::UInt, \l QMetaType::ULongLong \row
  • \l QMetaType::QFont
  • \l QMetaType::QString \row
  • \l QMetaType::Int
  • \l QMetaType::Bool, \l QMetaType::QChar, \l QMetaType::Double, \l QMetaType::LongLong, \l QMetaType::QString, \l QMetaType::UInt, \l QMetaType::ULongLong \row
  • \l QMetaType::QKeySequence
  • \l QMetaType::Int, \l QMetaType::QString \row
  • \l QMetaType::QVariantList
  • \l QMetaType::QStringList (if the list's items can be converted to QStrings) \row
  • \l QMetaType::LongLong
  • \l QMetaType::Bool, \l QMetaType::QByteArray, \l QMetaType::QChar, \l QMetaType::Double, \l QMetaType::Int, \l QMetaType::QString, \l QMetaType::UInt, \l QMetaType::ULongLong \row
  • \l QMetaType::QPoint
  • QMetaType::QPointF \row
  • \l QMetaType::QRect
  • QMetaType::QRectF \row
  • \l QMetaType::QString
  • \l QMetaType::Bool, \l QMetaType::QByteArray, \l QMetaType::QChar, \l QMetaType::QColor, \l QMetaType::QDate, \l QMetaType::QDateTime, \l QMetaType::Double, \l QMetaType::QFont, \l QMetaType::Int, \l QMetaType::QKeySequence, \l QMetaType::LongLong, \l QMetaType::QStringList, \l QMetaType::QTime, \l QMetaType::UInt, \l QMetaType::ULongLong, \l QMetaType::QUuid \row
  • \l QMetaType::QStringList
  • \l QMetaType::QVariantList, \l QMetaType::QString (if the list contains exactly one item) \row
  • \l QMetaType::QTime
  • \l QMetaType::QString \row
  • \l QMetaType::UInt
  • \l QMetaType::Bool, \l QMetaType::QChar, \l QMetaType::Double, \l QMetaType::Int, \l QMetaType::LongLong, \l QMetaType::QString, \l QMetaType::ULongLong \row
  • \l QMetaType::ULongLong
  • \l QMetaType::Bool, \l QMetaType::QChar, \l QMetaType::Double, \l QMetaType::Int, \l QMetaType::LongLong, \l QMetaType::QString, \l QMetaType::UInt \row
  • \l QMetaType::QUuid
  • \l QMetaType::QByteArray, \l QMetaType::QString \endtable

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.

See also
convert(), QSequentialIterable, Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(), QAssociativeIterable, Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE()

Definition at line 2434 of file qmetatype.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ canView()

bool QMetaType::canView ( QMetaType  fromType,
QMetaType  toType 
)
static

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().

See also
convert(), QSequentialIterable, Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(), QAssociativeIterable, Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE()

Definition at line 2336 of file qmetatype.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compare()

bool 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.

Note
If no less than operator was visible to the metatype declaration, values are unordered even if an equality operator visible to the declaration considers them equal: {compare() == 0} only agrees with equals() if the less than operator was visible.
Since
6.0
See also
equals(), isOrdered()
Deprecated:
Use the non-static compare method instead

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 751 of file qmetatype.cpp.

◆ construct()

void * QMetaType::construct ( void where,
const void copy = nullptr 
) const
Since
5.0

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).

Since
5.0
Deprecated:

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).

See also
destruct(), sizeOf()

Definition at line 678 of file qmetatype.cpp.

Here is the caller graph for this function:

◆ convert()

bool QMetaType::convert ( QMetaType  fromType,
const void from,
QMetaType  toType,
void to 
)
static
Deprecated:

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.

Since
5.2

Converts the object at from from fromType to the preallocated space at to typed toType. Returns true, if the conversion succeeded, otherwise false.

Both from and to have to be valid pointers.

Since
5.2

Definition at line 2226 of file qmetatype.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create()

void * QMetaType::create ( const void copy = nullptr) const
Since
5.0

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.

See also
QMetaType::destroy()
Deprecated:

Returns a copy of copy, assuming it is of type type. If copy is zero, creates a default constructed instance.

See also
destroy(), isRegistered(), Type

Definition at line 616 of file qmetatype.cpp.

Here is the caller graph for this function:

◆ debugStream()

bool QMetaType::debugStream ( QDebug dbg,
const void rhs 
)

Streams the object at rhs to the debug stream dbg. Returns true on success, otherwise false.

Since
5.2

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Deprecated:

Definition at line 1746 of file qmetatype.cpp.

◆ destroy()

void QMetaType::destroy ( void data) const
Since
5.0

Destroys the data, assuming it is of the type that this QMetaType instance was created for.

See also
QMetaType::create()
Deprecated:
Destroys the data, assuming it is of the type given.
See also
create(), isRegistered(), Type

Definition at line 639 of file qmetatype.cpp.

Here is the caller graph for this function:

◆ destruct()

void QMetaType::destruct ( void data) const
Since
5.0

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.

See also
QMetaType::construct()
Since
5.0
Deprecated:

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.

See also
construct()

Definition at line 705 of file qmetatype.cpp.

Here is the caller graph for this function:

◆ equals()

bool QMetaType::equals ( const void lhs,
const void rhs 
) const

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.

Since
6.0
See also
isEqualityComparable(), compare()

Definition at line 787 of file qmetatype.cpp.

◆ flags()

constexpr QMetaType::TypeFlags QMetaType::flags ( ) const
constexpr
Since
5.0

Returns flags of the type for which this QMetaType instance was constructed.

See also
QMetaType::TypeFlags, QMetaType::flags()

Definition at line 2516 of file qmetatype.h.

Here is the caller graph for this function:

◆ fromName()

QMetaType QMetaType::fromName ( QByteArrayView  typeName)
static

Returns a QMetaType matching typeName. The returned object is not valid if the typeName is not known to QMetaType

Definition at line 2789 of file qmetatype.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromType() [1/2]

template<typename T >
template< typename T > QMetaType QMetaType::fromType ( )
staticconstexpr
Since
5.15

Returns the QMetaType corresponding to the type in the template parameter.

Here is the caller graph for this function:

◆ fromType() [2/2]

template<typename T >
constexpr QMetaType QMetaType::fromType ( )
constexpr

Definition at line 2501 of file qmetatype.h.

◆ hasRegisteredConverterFunction() [1/2]

template<typename From , typename To >
bool QMetaType::hasRegisteredConverterFunction ( )
inlinestatic

Returns true, if the meta type system has a registered conversion from type From to type To.

Since
5.2 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 706 of file qmetatype.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasRegisteredConverterFunction() [2/2]

bool QMetaType::hasRegisteredConverterFunction ( QMetaType  fromType,
QMetaType  toType 
)
static

Returns true, if the meta type system has a registered conversion from meta type id fromType to toType

Since
5.2

Definition at line 2517 of file qmetatype.cpp.

Here is the call graph for this function:

◆ hasRegisteredDataStreamOperators()

bool QMetaType::hasRegisteredDataStreamOperators ( ) const
Since
6.1

Returns true, if the meta type system has registered data stream operators for this meta type.

Definition at line 2770 of file qmetatype.cpp.

Here is the call graph for this function:

◆ hasRegisteredDebugStreamOperator()

bool QMetaType::hasRegisteredDebugStreamOperator ( ) const
Deprecated:
Since
5.2

Returns true, if the meta type system has a registered debug stream operator for type T.

Deprecated:
Use QMetaType::hasRegisteredDebugStreamOperator() instead.

Returns true, if the meta type system has a registered debug stream operator for type id typeId.

Since
5.2
6.0

Returns true, if the meta type system has a registered debug stream operator for this meta type.

Definition at line 1788 of file qmetatype.cpp.

◆ hasRegisteredMutableViewFunction() [1/2]

template<typename From , typename To >
bool QMetaType::hasRegisteredMutableViewFunction ( )
inlinestatic

Returns true, if the meta type system has a registered mutable view on type From of type To.

Since
6.0 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 715 of file qmetatype.h.

Here is the caller graph for this function:

◆ hasRegisteredMutableViewFunction() [2/2]

bool QMetaType::hasRegisteredMutableViewFunction ( QMetaType  fromType,
QMetaType  toType 
)
static

Returns true, if the meta type system has a registered mutable view on meta type id fromType of meta type id toType.

Since
5.2

Definition at line 2534 of file qmetatype.cpp.

Here is the call graph for this function:

◆ id()

int QMetaType::id ( int  = 0) const
inline
Since
5.13

Returns id type hold by this QMetatype instance.

Definition at line 453 of file qmetatype.h.

Here is the caller graph for this function:

◆ iface()

const QtPrivate::QMetaTypeInterface* QMetaType::iface ( ) const
inline

Definition at line 740 of file qmetatype.h.

◆ isEqualityComparable()

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.

See also
equals(), isOrdered()

Definition at line 809 of file qmetatype.cpp.

◆ isOrdered()

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.

See also
compare(), isEqualityComparable()

Definition at line 820 of file qmetatype.cpp.

◆ isRegistered() [1/2]

bool QMetaType::isRegistered ( ) const
Since
5.0

Returns true if this QMetaType object contains valid information about a type, false otherwise.

Definition at line 521 of file qmetatype.cpp.

Here is the caller graph for this function:

◆ isRegistered() [2/2]

bool QMetaType::isRegistered ( int  type)
static

Returns true if the datatype with ID type is registered; otherwise returns false.

See also
type(), typeName(), Type

Definition at line 2620 of file qmetatype.cpp.

Here is the call graph for this function:

◆ isValid()

bool QMetaType::isValid ( ) const
Since
5.0

Returns true if this QMetaType object contains valid information about a type, false otherwise.

Definition at line 509 of file qmetatype.cpp.

Here is the caller graph for this function:

◆ load()

bool QMetaType::load ( QDataStream stream,
void data 
) const

Reads the object of this type from the given stream into data. Returns true if the object is loaded successfully; otherwise returns false.

The type must have been registered with Q_DECLARE_METATYPE() beforehand.

Normally, you should not need to call this function directly. Instead, use QVariant's operator>>(), which relies on load() to stream custom types.

See also
save()

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Deprecated:

Definition at line 2740 of file qmetatype.cpp.

Here is the call graph for this function:

◆ metaObject()

constexpr const QMetaObject * QMetaType::metaObject ( ) const
constexpr
Since
5.5

return 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 to in combinaison with QMetaObject::construct to create QObject of this type.

If the type is a Q_GADGET, flags() contains QMetaType::IsGadget, and this function returns its QMetaObject. This can be used to retrieve QMetaMethod and QMetaProperty and use them on a pointer of this type. (given by QVariant::data for example)

If the type is an enumeration, flags() contains QMetaType::IsEnumeration, and this function returns the QMetaObject of the enclosing object if the enum was registered as a Q_ENUM or \nullptr otherwise

See also
QMetaType::flags()

Definition at line 2521 of file qmetatype.h.

◆ name()

constexpr const char * QMetaType::name ( ) const
constexpr
Since
5.15

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.

See also
typeName()

Definition at line 2531 of file qmetatype.h.

Here is the caller graph for this function:

◆ registerConverter() [1/4]

template<typename From , typename To >
bool QMetaType::registerConverter ( )
inlinestatic
Since
5.2 Registers the possibility of an implicit conversion from type From to type To in the meta type system. Returns true if the registration succeeded, otherwise false.

Definition at line 540 of file qmetatype.h.

◆ registerConverter() [2/4]

template<typename From , typename To >
static bool QMetaType::registerConverter ( To(From::*)() const  function)
inlinestatic

Definition at line 547 of file qmetatype.h.

◆ registerConverter() [3/4]

template<typename From , typename To >
static bool QMetaType::registerConverter ( To(From::*)(bool *) const  function)
inlinestatic

Definition at line 583 of file qmetatype.h.

◆ registerConverter() [4/4]

template<typename From , typename To , typename UnaryFunction >
static bool QMetaType::registerConverter ( UnaryFunction  function)
inlinestatic

Definition at line 604 of file qmetatype.h.

◆ registerConverterFunction()

bool QMetaType::registerConverterFunction ( const ConverterFunction f,
QMetaType  from,
QMetaType  to 
)
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.

Since
5.2

Definition at line 1674 of file qmetatype.cpp.

Here is the call graph for this function:

◆ registerMutableView() [1/2]

template<typename From , typename To >
static bool QMetaType::registerMutableView ( To(From::*)()  function)
inlinestatic

Definition at line 565 of file qmetatype.h.

◆ registerMutableView() [2/2]

template<typename From , typename To , typename UnaryFunction >
static bool QMetaType::registerMutableView ( UnaryFunction  function)
inlinestatic

Definition at line 622 of file qmetatype.h.

◆ registerMutableViewFunction()

bool QMetaType::registerMutableViewFunction ( const MutableViewFunction f,
QMetaType  from,
QMetaType  to 
)
static

Registers function f as mutable view of type id to on type id from. Returns true if the registration succeeded, otherwise false.

Since
6.0

Definition at line 1707 of file qmetatype.cpp.

Here is the call graph for this function:

◆ registerNormalizedTypedef()

void QMetaType::registerNormalizedTypedef ( const QT_PREPEND_NAMESPACE(QByteArray) &  normalizedTypeName,
QMetaType  type 
)
static

Definition at line 2600 of file qmetatype.cpp.

Here is the call graph for this function:

◆ save()

bool QMetaType::save ( QDataStream stream,
const void data 
) const

Writes the object pointed to by data to the given stream. Returns true if the object is saved successfully; otherwise returns false.

The type must have been registered with Q_DECLARE_METATYPE() beforehand.

Normally, you should not need to call this function directly. Instead, use QVariant's operator<<(), which relies on save() to stream custom types.

See also
load()

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Deprecated:

Definition at line 2699 of file qmetatype.cpp.

Here is the call graph for this function:

◆ sizeOf()

constexpr qsizetype QMetaType::sizeOf ( ) const
constexpr
Since
5.0

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.

See also
QMetaType::construct(), QMetaType::sizeOf(), QMetaType::alignOf()
Since
5.0
Deprecated:

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.

See also
construct(), QMetaType::alignOf()

Definition at line 2506 of file qmetatype.h.

Here is the caller graph for this function:

◆ unregisterConverterFunction()

void QMetaType::unregisterConverterFunction ( QMetaType  from,
QMetaType  to 
)
static

Definition at line 1732 of file qmetatype.cpp.

Here is the call graph for this function:

◆ unregisterMetaType()

void QMetaType::unregisterMetaType ( QMetaType  type)
static

Definition at line 829 of file qmetatype.cpp.

◆ unregisterMutableViewFunction()

void QMetaType::unregisterMutableViewFunction ( QMetaType  from,
QMetaType  to 
)
static

Definition at line 1720 of file qmetatype.cpp.

Here is the call graph for this function:

◆ view()

bool QMetaType::view ( QMetaType  fromType,
void from,
QMetaType  toType,
void to 
)
static

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.

Since
6.0

Definition at line 2293 of file qmetatype.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator!=

bool QMetaType::operator!= ( QMetaType  a,
QMetaType  b 
)
friend
Since
5.15 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 QMetaType a represents a different type than the QMetaType b, otherwise returns false.

Definition at line 510 of file qmetatype.h.

◆ operator==

bool QMetaType::operator== ( QMetaType  a,
QMetaType  b 
)
friend
Since
5.15 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 QMetaType a represents the same type as the QMetaType b, otherwise returns false.

Definition at line 499 of file qmetatype.h.

◆ qMetaTypeId()

int qMetaTypeId ( )
related

\threadsafe

Since
4.1

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.

See also
Q_DECLARE_METATYPE(), QMetaType::type()

Definition at line 1302 of file qmetatype.h.

Here is the caller graph for this function:

◆ qRegisterMetaType() [1/2]

int qRegisterMetaType ( )
related

\threadsafe

Since
4.2

Call this function to register the type T. T must be declared with Q_DECLARE_METATYPE(). 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.

After a type has been registered, you can create and destroy objects of that type dynamically at run-time.

To use the type T in QVariant, using Q_DECLARE_METATYPE() is sufficient. To use the type T in queued signal and slot connections, {qRegisterMetaType<T>()} must be called before the first connection is established.

Also, to use type T with the QObject::property() API, {qRegisterMetaType<T>()} must be called before it is used, typically in the constructor of the class that uses T, or in the {main()} function.

See also
Q_DECLARE_METATYPE()

Definition at line 1312 of file qmetatype.h.

◆ qRegisterMetaType() [2/2]

int qRegisterMetaType ( const char *  typeName)
related

\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

Warning
This function is useful only for registering an alias (typedef) for every other use case Q_DECLARE_METATYPE and qMetaTypeId() should be used instead.
See also
{QMetaType::}{isRegistered()}, Q_DECLARE_METATYPE()

Definition at line 1291 of file qmetatype.h.

◆ QtPrivate::AssociativeValueTypeIsMetaType

template<typename , bool >
friend struct QtPrivate::AssociativeValueTypeIsMetaType
friend

Definition at line 725 of file qmetatype.h.

◆ QtPrivate::IsMetaTypePair

template<typename , bool >
friend struct QtPrivate::IsMetaTypePair
friend

Definition at line 726 of file qmetatype.h.

◆ QtPrivate::MetaTypeSmartPointerHelper

template<typename , typename >
friend struct QtPrivate::MetaTypeSmartPointerHelper
friend

Definition at line 727 of file qmetatype.h.

◆ QtPrivate::SequentialValueTypeIsMetaType

template<typename , bool >
friend struct QtPrivate::SequentialValueTypeIsMetaType
friend

Definition at line 724 of file qmetatype.h.

◆ QVariant

friend class QVariant
friend

Definition at line 744 of file qmetatype.h.


The documentation for this class was generated from the following files: