QMetaType Class▲
-
Header: QMetaType
-
CMake:
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
-
qmake: QT += core
-
Group: QMetaType is part of objectmodel
Detailed Description▲
The class is used as a helper to marshall types in https:// 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 https://() to make them available to https:// and other template-based functions. Call https://() 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:
int id = QMetaType::type("MyClass");
if (id != QMetaType::UnknownType) {
void *myClassPtr = QMetaType::create(id);
...
QMetaType::destroy(id, myClassPtr);
myClassPtr = 0;
}If we want the stream operators operator<<() and operator>>() to work on https:// objects that store custom types, the custom type must provide operator<<() and operator>>() operators.
See Also▲
See also https://(), https://(), https://(), https://()
Member Type Documentation▲
enum QMetaType::Type▲
These are the built-in types supported by https://:
|
Constant |
Value |
Description |
|---|---|---|
|
https://::Void |
43 |
void |
|
https://::Bool |
1 |
bool |
|
https://::Int |
2 |
int |
|
https://::UInt |
3 |
unsigned int |
|
https://::Double |
6 |
double |
|
https://::QChar |
7 |
QChar |
|
https://::QString |
10 |
QString |
|
https://::QByteArray |
12 |
QByteArray |
|
https://::Nullptr |
51 |
std::nullptr_t |
|
https://::VoidStar |
31 |
void * |
|
https://::Long |
32 |
long |
|
https://::LongLong |
4 |
LongLong |
|
https://::Short |
33 |
short |
|
https://::Char |
34 |
char |
|
https://::Char16 |
56 |
char16_t |
|
https://::Char32 |
57 |
char32_t |
|
https://::ULong |
35 |
unsigned long |
|
https://::ULongLong |
5 |
ULongLong |
|
https://::UShort |
36 |
unsigned short |
|
https://::SChar |
40 |
signed char |
|
https://::UChar |
37 |
unsigned char |
|
https://::Float |
38 |
float |
|
https://::QObjectStar |
39 |
https:// * |
|
https://::QVariant |
41 |
QVariant |
|
https://::QCursor |
0x100a |
QCursor |
|
https://::QDate |
14 |
QDate |
|
https://::QSize |
21 |
QSize |
|
https://::QTime |
15 |
QTime |
|
https://::QVariantList |
9 |
QVariantList |
|
https://::QPolygon |
0x1007 |
QPolygon |
|
https://::QPolygonF |
0x1016 |
QPolygonF |
|
https://::QColor |
0x1003 |
QColor |
|
https://::QColorSpace |
0x1017 |
QColorSpace (introduced in Qt 5.15) |
|
https://::QSizeF |
22 |
QSizeF |
|
https://::QRectF |
20 |
QRectF |
|
https://::QLine |
23 |
QLine |
|
https://::QTextLength |
0x100d |
QTextLength |
|
https://::QStringList |
11 |
QStringList |
|
https://::QVariantMap |
8 |
QVariantMap |
|
https://::QVariantHash |
28 |
QVariantHash |
|
https://::QIcon |
0x1005 |
QIcon |
|
https://::QPen |
0x100c |
QPen |
|
https://::QLineF |
24 |
QLineF |
|
https://::QTextFormat |
0x100e |
QTextFormat |
|
https://::QRect |
19 |
QRect |
|
https://::QPoint |
25 |
QPoint |
|
https://::QUrl |
17 |
QUrl |
|
https://::QRegularExpression |
44 |
QRegularExpression |
|
https://::QDateTime |
16 |
QDateTime |
|
https://::QPointF |
26 |
QPointF |
|
https://::QPalette |
0x1004 |
QPalette |
|
https://::QFont |
0x1000 |
QFont |
|
https://::QBrush |
0x1002 |
QBrush |
|
https://::QRegion |
0x1008 |
QRegion |
|
https://::QBitArray |
13 |
QBitArray |
|
https://::QImage |
0x1006 |
QImage |
|
https://::QKeySequence |
0x100b |
QKeySequence |
|
https://::QSizePolicy |
0x2000 |
QSizePolicy |
|
https://::QPixmap |
0x1001 |
QPixmap |
|
https://::QLocale |
18 |
QLocale |
|
https://::QBitmap |
0x1009 |
QBitmap |
|
https://::QTransform |
0x1010 |
QTransform |
|
https://::QMatrix4x4 |
0x1011 |
QMatrix4x4 |
|
https://::QVector2D |
0x1012 |
QVector2D |
|
https://::QVector3D |
0x1013 |
QVector3D |
|
https://::QVector4D |
0x1014 |
QVector4D |
|
https://::QQuaternion |
0x1015 |
QQuaternion |
|
https://::QEasingCurve |
29 |
QEasingCurve |
|
https://::QJsonValue |
45 |
QJsonValue |
|
https://::QJsonObject |
46 |
QJsonObject |
|
https://::QJsonArray |
47 |
QJsonArray |
|
https://::QJsonDocument |
48 |
QJsonDocument |
|
https://::QCborValue |
53 |
QCborValue |
|
https://::QCborArray |
54 |
QCborArray |
|
https://::QCborMap |
55 |
QCborMap |
|
https://::QCborSimpleType |
52 |
QCborSimpleType |
|
https://::QModelIndex |
42 |
QModelIndex |
|
https://::QPersistentModelIndex |
50 |
QPersistentModelIndex (introduced in Qt 5.5) |
|
https://::QUuid |
30 |
QUuid |
|
https://::QByteArrayList |
49 |
QByteArrayList |
|
https://::User |
65536 |
Base value for user types |
|
https://::UnknownType |
0 |
This is an invalid type id. It is returned from https:// for types that are not registered |
Additional types can be registered using https://().
See Also▲
See also https://(), https://()
enum QMetaType::TypeFlag▲
flags QMetaType::TypeFlags
The enum describes attributes of a type supported by https://.
|
Constant |
Value |
Description |
|---|---|---|
|
https://::NeedsConstruction |
0x1 |
This type has non-trivial constructors. If the flag is not set instances can be safely initialized with memset to 0. |
|
https://::NeedsDestruction |
0x2 |
This type has a non-trivial destructor. If the flag is not set calls to the destructor are not necessary before discarding objects. |
|
https://::RelocatableType |
0x4 |
An instance of a type having this attribute can be safely moved to a different memory location using memcpy. |
|
https://::IsEnumeration |
0x10 |
This type is an enumeration. |
|
https://::IsUnsignedEnumeration |
0x100 |
If the type is an Enumeration, its underlying type is unsigned. |
|
https://::PointerToQObject |
0x8 |
This type is a pointer to a derived of https://. |
|
https://::IsPointer |
0x800 |
This type is a pointer to another type. |
The TypeFlags type is a typedef for https://<TypeFlag>. It stores an OR combination of TypeFlag values.
Member Function Documentation▲
[explicit, since 5.0] QMetaType::QMetaType(int typeId)▲
Constructs a https:// object that contains all information about type typeId.
This function was introduced in Qt 5.0.
[constexpr, since 6.0] qsizetype QMetaType::alignOf() const▲
Returns the alignment of the type in bytes (i.e. alignof(T), where T is the actual type for which this https:// instance was constructed for).
This function is typically used together with construct() to perform low-level management of the memory used by a type.
This function was introduced in Qt 6.0.
See Also▲
See also https://(), https://()
[static] bool QMetaType::canConvert(QMetaType fromType, QMetaType toType)▲
Returns true if https:// can convert from fromType to toType.
The following conversions are supported by Qt:
|
Type |
Automatically Cast To |
|---|---|
|
https:// |
https://, https://, https://, https://, https://, https://, https:// |
|
https:// |
https://, https://, https://, https://, https://, https://, https:// |
|
https:// |
https://, https://, https://, https://, https:// |
|
https:// |
https:// |
|
https:// |
https://, https:// |
|
https:// |
https://, https://, https:// |
|
https:// |
https://, https://, https://, https://, https://, https:// |
|
https:// |
https:// |
|
https:// |
https://, https://, https://, https://, https://, https://, https:// |
|
https:// |
https://, https:// |
|
https:// |
https:// (if the list's items can be converted to QStrings) |
|
https:// |
https://, https://, https://, https://, https://, https://, https://, https:// |
|
https:// |
https:// |
|
https:// |
https:// |
|
https:// |
https://, https://, https://, https://, https://, https://, https://, https://, https://, https://, https://, https://, https://, https://, https://, https:// |
|
https:// |
https://, https:// (if the list contains exactly one item) |
|
https:// |
https:// |
|
https:// |
https://, https://, https://, https://, https://, https://, https:// |
|
https:// |
https://, https://, https://, https://, https://, https://, https:// |
|
https:// |
https://, https:// |
Casting between primitive type (int, float, bool etc.) is supported.
Converting between pointers of types derived from https:// will also return true for this function if a https:// 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 https://.
Similarly, a cast from an associative container will also return true for this function the toType is https:// or https://.
See Also▲
See also https://(), https://, https://(), https://, https://()
[static] bool QMetaType::canView(QMetaType fromType, QMetaType toType)▲
Returns true if https:// can create a mutable view of type toType on type fromType.
Converting between pointers of types derived from https:// will return true for this function if a https:// from the type described by fromType to the type described by toType would succeed.
You can create a mutable view of type https:// on any container registered with https://().
Similarly you can create a mutable view of type https:// on any container registered with https://().
See Also▲
See also https://(), https://, https://(), https://, https://()
[since 6.0] QPartialOrdering QMetaType::compare(const void *lhs, const void *rhs) const▲
Compares the objects at lhs and rhs for ordering.
Returns https:// if comparison is not supported or the values are unordered. Otherwise, returns https://, https:// or https:// 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.
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 https://() if the less than operator was visible.
This function was introduced in Qt 6.0.
See Also▲
See also https://(), https://()
[since 5.0] void *QMetaType::construct(void *where, const void *copy = nullptr) const▲
Constructs a value of the type that this https:// 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 https://().
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).
This function was introduced in Qt 5.0.
[static, since 5.2] bool QMetaType::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. Returns true, if the conversion succeeded, otherwise false.
This function was introduced in Qt 5.2.
[since 5.0] void *QMetaType::create(const void *copy = nullptr) const▲
Returns a copy of copy, assuming it is of the type that this https:// instance was created for. If copy is nullptr, creates a default constructed instance.
This function was introduced in Qt 5.0.
See Also▲
See also https://()
[since 5.2] bool QMetaType::debugStream(QDebug &dbg, const void *rhs)▲
Streams the object at rhs to the debug stream dbg. Returns true on success, otherwise false.
This function was introduced in Qt 5.2.
[since 5.0] void QMetaType::destroy(void *data) const▲
Destroys the data, assuming it is of the type that this https:// instance was created for.
This function was introduced in Qt 5.0.
See Also▲
See also https://()
[since 5.0] void QMetaType::destruct(void *data) const▲
Destructs the value, located at data, assuming that it is of the type for which this https:// instance was constructed for.
Unlike destroy(), this function only invokes the type's destructor, it doesn't invoke the delete operator.
This function was introduced in Qt 5.0.
See Also▲
See also https://()
[since 6.0] 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 https://() for details) they are not equal.
Returns true if the two objects compare equal, otherwise false.
This function was introduced in Qt 6.0.
See Also▲
See also https://(), https://()
[constexpr, since 5.0] QMetaType::TypeFlags QMetaType::flags() const▲
Returns flags of the type for which this https:// instance was constructed.
This function was introduced in Qt 5.0.
See Also▲
See also https://, QMetaType::flags()
[static] QMetaType QMetaType::fromName(QByteArrayView typeName)▲
Returns a https:// matching typeName. The returned object is not valid if the typeName is not known to https://
[static constexpr, since 5.15] QMetaType QMetaType::fromType()▲
Returns the https:// corresponding to the type in the template parameter.
This function was introduced in Qt 5.15.
[static, since 5.2] bool QMetaType::hasRegisteredConverterFunction(QMetaType fromType, QMetaType toType)▲
Returns true, if the meta type system has a registered conversion from meta type id fromType to toType
This function was introduced in Qt 5.2.
[static, since 5.2] bool QMetaType::hasRegisteredConverterFunction()▲
Returns true, if the meta type system has a registered conversion from type From to type To.
This is an overloaded function.
This function was introduced in Qt 5.2.
[since 6.0] bool QMetaType::hasRegisteredDebugStreamOperator() const▲
Returns true, if the meta type system has a registered debug stream operator for this meta type.
This function was introduced in Qt 6.0.
[static, since 5.2] bool QMetaType::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.
This function was introduced in Qt 5.2.
[static, since 6.0] bool QMetaType::hasRegisteredMutableViewFunction()▲
Returns true, if the meta type system has a registered mutable view on type From of type To.
This is an overloaded function.
This function was introduced in Qt 6.0.
[since 5.13] int QMetaType::id() const▲
Returns id type hold by this QMetatype instance.
This function was introduced in Qt 5.13.
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▲
See also https://(), https://()
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▲
See also https://(), https://()
[static] bool QMetaType::isRegistered(int type)▲
Returns true if the datatype with ID type is registered; otherwise returns false.
See Also▲
See also https://(), https://(), https://
[since 5.0] bool QMetaType::isRegistered() const▲
Returns true if this https:// object contains valid information about a type, false otherwise.
This function was introduced in Qt 5.0.
[since 5.0] bool QMetaType::isValid() const▲
Returns true if this https:// object contains valid information about a type, false otherwise.
This function was introduced in Qt 5.0.
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 https://() beforehand.
Normally, you should not need to call this function directly. Instead, use https://'s operator>>(), which relies on load() to stream custom types.
See Also▲
See also https://()
[constexpr, since 5.5] const QMetaObject *QMetaType::metaObject() const▲
return a https:// relative to this type.
If the type is a pointer type to a subclass of https://, https://() contains https:// and this function returns the corresponding https://. This can be used to in combinaison with QMetaObject::construct to create https:// of this type.
If the type is a https://, https://() contains https://, and this function returns its https://. This can be used to retrieve https:// and https:// and use them on a pointer of this type. (given by https:// for example)
If the type is an enumeration, https://() contains https://, and this function returns the https:// of the enclosing object if the enum was registered as a https:// or nullptr otherwise
This function was introduced in Qt 5.5.
See Also▲
See also https://()
[constexpr, since 5.15] const char *QMetaType::name() const▲
Returns the type name associated with this https://, or a null pointer if no matching type was found. The returned pointer must not be deleted.
This function was introduced in Qt 5.15.
See Also▲
See also https://()
[static, since 5.2] bool QMetaType::registerConverter()▲
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.
This function was introduced in Qt 5.2.
[static, since 5.2] bool QMetaType::registerConverter(MemberFunction function)▲
This is an overloaded function.
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.
This function was introduced in Qt 5.2.
[static, since 5.2] bool QMetaType::registerConverter(MemberFunctionOk function)▲
This is an overloaded function.
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.
This function was introduced in Qt 5.2.
[static, since 5.2] bool QMetaType::registerConverter(UnaryFunction function)▲
This is an overloaded function.
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.
This function was introduced in Qt 5.2.
[static, since 6.0] bool QMetaType::registerMutableView(MemberFunction function)▲
This is an overloaded function.
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.
This function was introduced in Qt 6.0.
[static, since 6.0] bool QMetaType::registerMutableView(MemberFunctionOk function)▲
This is an overloaded function.
Registers a method function like To From::function(bool *ok) as mutable view of type To on type From in the meta type system. Returns true if the registration succeeded, otherwise false.
This function was introduced in Qt 6.0.
[static, since 6.0] bool QMetaType::registerMutableView(UnaryFunction function)▲
This is an overloaded function.
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.
This function was introduced in Qt 6.0.
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 https://() beforehand.
Normally, you should not need to call this function directly. Instead, use https://'s operator<<(), which relies on save() to stream custom types.
See Also▲
See also https://()
[constexpr, since 5.0] qsizetype QMetaType::sizeOf() const▲
Returns the size of the type in bytes (i.e. sizeof(T), where T is the actual type for which this https:// instance was constructed for).
This function is typically used together with construct() to perform low-level management of the memory used by a type.
This function was introduced in Qt 5.0.
See Also▲
See also https://(), QMetaType::sizeOf(), https://()
[static, since 6.0] bool QMetaType::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. Returns true if the conversion succeeded, otherwise false.
This function was introduced in Qt 6.0.
Related Non-Members▲
[constexpr] int qMetaTypeId()▲
Returns the meta type id of type T at compile time. If the type was not declared with https://(), compilation will fail.
Typical usage:
int id = qMetaTypeId<QString>(); // id is now QMetaType::QString
id = qMetaTypeId<MyStruct>(); // compile error if MyStruct not declaredQMetaType::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▲
See also https://(), https://()
int qRegisterMetaType(const char *typeName)▲
Registers the type name typeName for the type T. Returns the internal ID used by https://. 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 https://() 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:
qRegisterMetaType<MyClass>("MyClass");This function is useful to register typedefs so they can be used by https://, or in QueuedConnections
typedef QString CustomString;
qRegisterMetaType<CustomString>("CustomString");This function is useful only for registering an alias (typedef) for every other use case https:// and https://() should be used instead.
See Also▲
See also https://(), https://()
[constexpr] int qRegisterMetaType()▲
Call this function to register the type T. T must be declared with https://(). Returns the meta type Id.
Example:
int id = qRegisterMetaType<MyStruct>();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 https://() 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 https://, using https://() 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 https://() 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▲
See also https://()
[since 5.15] bool operator!=(QMetaType a, QMetaType b)▲
This is an overloaded function.
Returns true if the https:// a represents a different type than the https:// b, otherwise returns false.
This function was introduced in Qt 5.15.
[since 5.15] bool operator==(QMetaType a, QMetaType b)▲
This is an overloaded function.
Returns true if the https:// a represents the same type as the https:// b, otherwise returns false.
This function was introduced in Qt 5.15.
Macro Documentation▲
Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE(Container)▲
This macro makes the container Container known to https:// as an associative container. This makes it possible to put an instance of Container<T, U> into a https://, if T and U are themselves known to https://.
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>
Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE(std::unordered_map)
void someFunc()
{
std::unordered_map<int, bool> container;
QVariant var = QVariant::fromValue(container);
// ...
}Q_DECLARE_METATYPE(Type)▲
This macro makes the type Type known to https:// 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 https://.
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 https://() 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 https://.
Adding a Q_DECLARE_METATYPE() makes the type known to all template based functions, including https://. Note that if you intend to use the type in queued signal and slot connections or in https://'s property system, you also have to call https://() since the names are resolved at runtime.
This example shows a typical use case of Q_DECLARE_METATYPE():
struct MyStruct
{
int i;
...
};
Q_DECLARE_METATYPE(MyStruct)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 https://, it can be used in https://:
MyStruct s;
QVariant var;
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:
-
Pointers to classes derived from https://
-
https://<T>, https://<T>, https://<T> or https://<T> where T is a registered meta type
-
https://<T1, T2>, https://<T1, T2> or https://<T1, T2> where T1 and T2 are registered meta types
-
https://<T>, https://<T>, https://<T>, where T is a class that derives from https://
-
Enumerations registered with https:// or https://
-
Classes that have a https:// macro
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:
QDataStream &operator<<(QDataStream &out, const MyClass &myObj);
QDataStream &operator>>(QDataStream &in, MyClass &myObj);See Also▲
See also https://()
[since 5.0] Q_DECLARE_OPAQUE_POINTER(PointerType)▲
This macro enables pointers to forward-declared types (PointerType) to be registered with https:// using either https://() or https://().
This macro was introduced in Qt 5.0.
See Also▲
See also https://(), https://()
Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(Container)▲
This macro makes the container Container known to https:// as a sequential container. This makes it possible to put an instance of Container<T> into a https://, if T itself is known to https://.
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>
Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(std::deque)
void someFunc()
{
std::deque<QFile*> container;
QVariant var = QVariant::fromValue(container);
// ...
}Q_DECLARE_SMART_POINTER_METATYPE(SmartPointer)▲
This macro makes the smart pointer SmartPointer known to https:// as a smart pointer. This makes it possible to put an instance of SmartPointer<T> into a https://, if T is a type which inherits https://.
Note that the https://, https:// and https:// 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>
Q_DECLARE_SMART_POINTER_METATYPE(std::shared_ptr)
void someFunc()
{
auto smart_ptr = std::make_shared<QFile>();
QVariant var = QVariant::fromValue(smart_ptr);
// ...
if (var.canConvert<QObject*>()) {
QObject *sp = var.value<QObject*>();
qDebug() << sp->metaObject()->className(); // Prints 'QFile'.
}
}Obsolete Members for QMetaType▲
The following members of class https:// are deprecated. We strongly advise against using them in new code.
Obsolete Member Function Documentation▲
[static] bool QMetaType::compare(const void *lhs, const void *rhs, int typeId, int *result)▲
This function is deprecated. We strongly advise against using it in new code.
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.
[static, since 5.0] void *QMetaType::construct(int type, void *where, const void *copy)▲
This function is deprecated. We strongly advise against using it in new code.
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 https://() 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 https://().
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).
This function was introduced in Qt 5.0.
See Also▲
See also https://(), https://()
[static, since 5.2] bool QMetaType::convert(const void *from, int fromTypeId, void *to, int toTypeId)▲
This function is deprecated. We strongly advise against using it in new code.
Converts the object at from from fromTypeId to the preallocated space at to typed toTypeId. Returns true, if the conversion succeeded, otherwise false.
This function was introduced in Qt 5.2.
[static] void *QMetaType::create(int type, const void *copy = nullptr)▲
This function is deprecated. We strongly advise against using it in new code.
Returns a copy of copy, assuming it is of type type. If copy is zero, creates a default constructed instance.
See Also▲
See also https://(), https://(), https://
[static] bool QMetaType::debugStream(QDebug &dbg, const void *rhs, int typeId)▲
This function is deprecated. We strongly advise against using it in new code.
This is an overloaded function.
[static] void QMetaType::destroy(int type, void *data)▲
This function is deprecated. We strongly advise against using it in new code.
Destroys the data, assuming it is of the type given.
See Also▲
See also https://(), https://(), https://
[static, since 5.0] void QMetaType::destruct(int type, void *where)▲
This function is deprecated. We strongly advise against using it in new code.
Destructs the value of the given type, located at where.
Unlike https://(), this function only invokes the type's destructor, it doesn't invoke the delete operator.
This function was introduced in Qt 5.0.
See Also▲
See also https://()
[static, since 5.2] bool QMetaType::hasRegisteredDebugStreamOperator()▲
This function is deprecated. We strongly advise against using it in new code.
Returns true, if the meta type system has a registered debug stream operator for type T.
This function was introduced in Qt 5.2.
[static, since 5.2] bool QMetaType::hasRegisteredDebugStreamOperator(int typeId)▲
This function is deprecated. We strongly advise against using it in new code.
Use https://() instead.
Returns true, if the meta type system has a registered debug stream operator for type id typeId.
This function was introduced in Qt 5.2.
[static] bool QMetaType::load(QDataStream &stream, int type, void *data)▲
This function is deprecated. We strongly advise against using it in new code.
This is an overloaded function.
[static, since 5.0] const QMetaObject *QMetaType::metaObjectForType(int type)▲
This function is deprecated. We strongly advise against using it in new code.
returns https:// for type
This function was introduced in Qt 5.0.
See Also▲
See also https://()
[static] bool QMetaType::save(QDataStream &stream, int type, const void *data)▲
This function is deprecated. We strongly advise against using it in new code.
This is an overloaded function.
[static, since 5.0] int QMetaType::sizeOf(int type)▲
This function is deprecated. We strongly advise against using it in new code.
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 https://() to perform low-level management of the memory used by a type.
This function was introduced in Qt 5.0.
See Also▲
See also https://(), https://()
[static] int QMetaType::type(const char *typeName)▲
This function is deprecated. We strongly advise against using it in new code.
Returns a handle to the type called typeName, or https:// if there is no such type.
See Also▲
See also https://(), https://(), https://
[static, since 5.5] int QMetaType::type(const ::QByteArray &typeName)▲
This function is deprecated. We strongly advise against using it in new code.
This is an overloaded function.
Returns a handle to the type called typeName, or 0 if there is no such type.
This function was introduced in Qt 5.5.
See Also▲
See also https://(), https://()
[static, since 5.0] QMetaType::TypeFlags QMetaType::typeFlags(int type)▲
This function is deprecated. We strongly advise against using it in new code.
Returns flags of the given type.
This function was introduced in Qt 5.0.
See Also▲
See also https://
[static] const char *QMetaType::typeName(int typeId)▲
This function is deprecated. We strongly advise against using it in new code.
Returns the type name associated with the given typeId, or a null pointer if no matching type was found. The returned pointer must not be deleted.
See Also▲
See also https://(), https://(), https://, https://()


