From 4c3c63d4cbb81b38e88e06b72749e7e01497b6f1 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 4 Dec 2019 09:49:34 +0100 Subject: QMetaType: add more static-less API In prevision to Qt6 which is going to discourrage the use of the integer id, add some missing API to the staticless QMetaType API: - Add a way to construct a QMetaType from a type without calling qMetaTypeId: QMetaType::fromType() - Add equality operators - Add a QMetaType::name() function - Add a default constructor (by adding a default parameter to the existing ctor) Change-Id: I95487c1c31bdf0d773717daa9d5452cbced30673 Reviewed-by: Lars Knoll --- src/corelib/kernel/qmetatype.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/corelib/kernel/qmetatype.h') diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 240828bc9a..825f767425 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -572,7 +572,7 @@ public: static bool load(QDataStream &stream, int type, void *data); #endif - explicit QMetaType(const int type); // ### Qt6: drop const + explicit QMetaType(const int type = QMetaType::UnknownType); // ### Qt6: drop const inline ~QMetaType(); inline bool isValid() const; @@ -581,12 +581,24 @@ public: inline int sizeOf() const; inline TypeFlags flags() const; inline const QMetaObject *metaObject() const; + QT_PREPEND_NAMESPACE(QByteArray) name() const; inline void *create(const void *copy = nullptr) const; inline void destroy(void *data) const; inline void *construct(void *where, const void *copy = nullptr) const; inline void destruct(void *data) const; + template + static QMetaType fromType() + { return QMetaType(qMetaTypeId()); } + + friend bool operator==(const QMetaType &a, const QMetaType &b) + { return a.m_typeId == b.m_typeId; } + + friend bool operator!=(const QMetaType &a, const QMetaType &b) + { return a.m_typeId != b.m_typeId; } + + public: template static bool registerComparators() -- cgit v1.2.3