Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QMetaType Class Reference

\inmodule QtCore More...

#include <qmetatype.h>

+ Collaboration diagram for QMetaType:

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 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
 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::QMetaTypeInterfaceiface () 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)
 

Detailed Description

\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 (type.isValid()) {
void *myClassPtr = type.create();
...
type.destroy(myClassPtr);
myClassPtr = nullptr;
}

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 338 of file qmetatype.h.

Member Typedef Documentation

◆ ConverterFunction

using QMetaType::ConverterFunction = std::function<bool(const void *src, void *target)>

Definition at line 557 of file qmetatype.h.

◆ MutableViewFunction

using QMetaType::MutableViewFunction = std::function<bool(void *src, void *target)>

Definition at line 560 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():

struct MyStruct
{
int i;
...
};

If MyStruct is in a namespace, the Q_DECLARE_METATYPE() macro has to be outside the namespace:

namespace MyNamespace
{
...
}
Q_DECLARE_METATYPE(MyNamespace::MyStruct)

Since {MyStruct} is now known to QMetaType, it can be used in QVariant:

var.setValue(s); // copy s into the variant
...
// retrieve the value
MyStruct s2 = var.value<MyStruct>();

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 std::pair<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():

#include <deque>
void someFunc()
{
std::deque<QFile*> container;
// ...
}

\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():

#include <unordered_list>
void someFunc()
{
std::unordered_map<int, bool> container;
// ...
}

\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():

#include <memory>
void someFunc()
{
auto smart_ptr = std::make_shared<QFile>();
// ...
if (var.canConvert<QObject*>()) {
qDebug() << sp->metaObject()->className(); // Prints 'QFile'.
}
}
\inmodule QtCore
Definition qmetatype.h:338
static QMetaType fromName(QByteArrayView name)
Returns a QMetaType matching typeName.
#define Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(SINGLE_ARG_TEMPLATE)
Definition qmetatype.h:1672
#define Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE(TEMPLATENAME)
Definition qmetatype.h:1696
#define Q_DECLARE_SMART_POINTER_METATYPE(SMART_POINTER)
Definition qmetatype.h:1625
#define sp
qRegisterMetaType< CustomString >("CustomString")
void someFunc()
[9]
qRegisterMetaType< MyClass >("MyClass")
[3]
QString CustomString
[8]

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

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

Definition at line 342 of file qmetatype.h.

◆ 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
Before Qt 6.5, both the NeedsConstruction and NeedsDestruction flags were incorrectly set if the either copy construtor or destructor were non-trivial (that is, if the type was not trivial).

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.

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

Definition at line 396 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 3275 of file qmetatype.cpp.

◆ QMetaType() [2/3]

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

Definition at line 457 of file qmetatype.h.

◆ QMetaType() [3/3]

QMetaType::QMetaType ( )
constexprdefault
Since
6.0

Constructs a default, invalid, QMetaType object.

Member Function Documentation

◆ alignOf()

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

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

◆ compare()

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.

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.

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 754 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()
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 690 of file qmetatype.cpp.

◆ convert()

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

Converts the object at from from fromType to the preallocated space at to typed toType.

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

Returns true, if the conversion succeeded, otherwise false.

Both from and to have to be valid pointers.

Since
5.2
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

Definition at line 2363 of file qmetatype.cpp.

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

◆ debugStream()

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

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.

Since
5.2
Deprecated
Deprecated

Definition at line 1858 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
Deprecated
Destroys the data, assuming it is of the type given.
See also
create(), isRegistered(), Type

Definition at line 656 of file qmetatype.cpp.

◆ 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()
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 712 of file qmetatype.cpp.

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

◆ flags()

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

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.

See also
QMetaType::TypeFlags, QMetaType::flags(), isDefaultConstructible(), isCopyConstructible(), isMoveConstructible(), isDestructible(), isEqualityComparable(), isOrdered()

Definition at line 2690 of file qmetatype.h.

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

◆ fromType()

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

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

Definition at line 2664 of file qmetatype.h.

◆ hasRegisteredConverterFunction() [1/2]

template<typename From , typename To >
static 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 737 of file qmetatype.h.

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

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

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

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

Definition at line 1900 of file qmetatype.cpp.

◆ hasRegisteredMutableViewFunction() [1/2]

template<typename From , typename To >
static 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 746 of file qmetatype.h.

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

◆ id()

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

Returns id type held by this QMetatype instance.

Definition at line 476 of file qmetatype.h.

◆ iface()

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

Definition at line 771 of file qmetatype.h.

◆ isCopyConstructible()

bool QMetaType::isCopyConstructible ( ) const
inlinenoexcept
Since
6.5

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.

See also
flags(), isDefaultConstructible(), isMoveConstructible(), isDestructible()

Definition at line 495 of file qmetatype.h.

◆ isDefaultConstructible()

bool QMetaType::isDefaultConstructible ( ) const
inlinenoexcept
Since
6.5

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.

See also
flags(), isCopyConstructible(), isMoveConstructible(), isDestructible()

Definition at line 494 of file qmetatype.h.

◆ isDestructible()

bool QMetaType::isDestructible ( ) const
inlinenoexcept
Since
6.5

Returns true if this type can be destroyed. If it can be, then destroy() and destruct() can be called.

See also
flags(), isDefaultConstructible(), isCopyConstructible(), isMoveConstructible()

Definition at line 497 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 874 of file qmetatype.cpp.

◆ isMoveConstructible()

bool QMetaType::isMoveConstructible ( ) const
inlinenoexcept
Since
6.5

Returns true if this type can be move-constructed. QMetaType currently does not have an API to make use of this trait.

See also
flags(), isDefaultConstructible(), isCopyConstructible(), isDestructible()

Definition at line 496 of file qmetatype.h.

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

◆ isRegistered() [1/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 2821 of file qmetatype.cpp.

◆ isRegistered() [2/2]

bool QMetaType::isRegistered ( QT6_DECL_NEW_OVERLOAD ) const
inlinenoexcept

◆ isValid()

bool QMetaType::isValid ( QT6_DECL_NEW_OVERLOAD ) const
constexprnoexcept
Since
5.0

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

See also
isRegistered()

Definition at line 2670 of file qmetatype.h.

◆ load()

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.

See also
save()
Deprecated
Deprecated

Definition at line 2941 of file qmetatype.cpp.

◆ metaObject()

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

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.

See also
QMetaType::flags()

Definition at line 2695 of file qmetatype.h.

◆ name()

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 2712 of file qmetatype.h.

Referenced by testing.tools.encode_pdf_filter._PdfStream::RegisterByName().

+ Here is the caller graph for this function:

◆ registerConverter() [1/4]

template<typename From , typename To >
static 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.
class Counter {
int number = 0;
public:
int value() const { return number; }
operator int() const { return value(); }
void increment() {++number;}
};

Definition at line 564 of file qmetatype.h.

◆ registerConverter() [2/4]

template<typename From , typename To >
static bool QMetaType::registerConverter ( To(From::* function )() const)
inlinestatic
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. Registers a method function like To From::function() const as converter from type From to type To in the meta type system. Returns true if the registration succeeded, otherwise false.
struct Coordinates {
int x;
int y;
int z;
QString toString() const { return u"[x: %1; y: %2, z: %3]"_s.arg(QString::number(x),
};

Definition at line 571 of file qmetatype.h.

◆ registerConverter() [3/4]

template<typename From , typename To >
static bool QMetaType::registerConverter ( To(From::* function )(bool *) const)
inlinestatic
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. Registers a method function like To From::function(bool *ok) const as converter from type From to type To in the meta type system. Returns true if the registration succeeded, otherwise false.

The ok pointer can be used by the function to indicate whether the conversion succeeded.

struct BigNumber {
long long l;
int toInt(bool *ok = nullptr) const {
const bool canConvertSafely = l < std::numeric_limits<int>::max();
if (ok)
*ok = canConvertSafely;
return l;
}
};

Definition at line 607 of file qmetatype.h.

◆ registerConverter() [4/4]

template<typename From , typename To , typename UnaryFunction >
static bool QMetaType::registerConverter ( UnaryFunction function)
inlinestatic
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. Registers a unary function object function as converter from type From to type To in the meta type system. Returns 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.

});
[](const QJsonValue &value) -> std::optional<QPointF> {
const auto object = value.toObject();
if (!object.contains("x") || !object.contains("y"))
return std::nullopt; // The conversion fails if the required properties are missing
return QPointF{object["x"].toDouble(), object["y"].toDouble()};
});

Definition at line 628 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 1775 of file qmetatype.cpp.

◆ registerMutableView() [1/2]

template<typename From , typename To >
static bool QMetaType::registerMutableView ( To(From::* function )())
inlinestatic
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. Registers a method function like {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.

◆ registerMutableView() [2/2]

template<typename From , typename To , typename UnaryFunction >
static bool QMetaType::registerMutableView ( UnaryFunction function)
inlinestatic
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. Registers a unary function object 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 653 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 1808 of file qmetatype.cpp.

◆ registerNormalizedTypedef()

void QMetaType::registerNormalizedTypedef ( const QT_PREPEND_NAMESPACE(QByteArray) & normalizedTypeName,
QMetaType type )
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.

◆ registerType()

void QMetaType::registerType ( ) const
inline
Since
6.5

Registers this QMetaType with the type registry so it can be found by name, using QMetaType::fromName().

See also
qRegisterMetaType()

Definition at line 466 of file qmetatype.h.

◆ save()

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.

See also
load()
Deprecated
Deprecated

Definition at line 2903 of file qmetatype.cpp.

◆ sizeOf()

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()
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 2680 of file qmetatype.h.

◆ underlyingType()

QMetaType QMetaType::underlyingType ( ) const
Since
6.6

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.

◆ unregisterConverterFunction()

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

Invoked automatically when a converter function object is destroyed.

Definition at line 1833 of file qmetatype.cpp.

◆ unregisterMetaType()

void QMetaType::unregisterMetaType ( QMetaType type)
static

Definition at line 894 of file qmetatype.cpp.

◆ unregisterMutableViewFunction()

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

Definition at line 1821 of file qmetatype.cpp.

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

Friends And Related Symbol Documentation

◆ comparesEqual

bool comparesEqual ( const QMetaType & lhs,
const QMetaType & rhs )
friend

Definition at line 522 of file qmetatype.h.

◆ operator<<

Q_CORE_EXPORT QDebug operator<< ( QDebug d,
QMetaType m )
friend
Since
6.5 Writes the QMetaType m to the stream d, and returns the stream.

Definition at line 1847 of file qmetatype.cpp.

◆ qHash()

size_t qHash ( QMetaType type,
size_t seed = 0 )
related
Since
6.4

Returns the hash value for the type, using seed to seed the calculation.

Definition at line 2722 of file qmetatype.h.

◆ qMetaTypeId()

template< typename T > 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:

int id = qMetaTypeId<QString>(); // id is now QMetaType::QString
id = qMetaTypeId<MyStruct>(); // compile error if MyStruct not declared

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 1382 of file qmetatype.h.

◆ qRegisterMetaType() [1/3]

template< typename T > int qRegisterMetaType ( )
related

\threadsafe

Since
4.2

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

See also
Q_DECLARE_METATYPE()

Definition at line 1395 of file qmetatype.h.

◆ qRegisterMetaType() [2/3]

template< typename T > int qRegisterMetaType ( const char * typeName)
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

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 1371 of file qmetatype.h.

◆ qRegisterMetaType [3/3]

int qRegisterMetaType ( QMetaType meta)
friend

\threadsafe

Since
6.5

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.

◆ QtPrivate::AssociativeValueTypeIsMetaType

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

Definition at line 756 of file qmetatype.h.

◆ QtPrivate::IsMetaTypePair

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

Definition at line 757 of file qmetatype.h.

◆ QtPrivate::MetaTypeSmartPointerHelper

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

Definition at line 758 of file qmetatype.h.

◆ QtPrivate::SequentialValueTypeIsMetaType

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

Definition at line 755 of file qmetatype.h.

◆ QVariant

friend class QVariant
friend

Definition at line 795 of file qmetatype.h.


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