From 637ccf5332010b2b6480697993a779457702fd70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20De=20Canni=C3=A8re?= Date: Wed, 3 Dec 2025 12:35:16 +0100 Subject: QMetaObject: Include a class def's hash in the meta object The hash has the following format $, where hash_revision is an integer and hash_b64 is the base64 encoding of the hash. MetaObjects built using QMetaObjectBuilder do not yet support the hash. That will need to be added at a later point. Task-number: QTBUG-142186 Change-Id: Ifafc7df2202decf48e8a1a45e652c2f61c5cea64 Reviewed-by: Thiago Macieira Reviewed-by: Fabian Kosmale --- src/corelib/kernel/qmetaobject.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/corelib/kernel/qmetaobject.cpp') diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 24cc58829c8..c7e50788b45 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -469,6 +469,33 @@ QMetaType QMetaObject::metaType() const } } +static inline QByteArrayView objectMetaObjectHash(const QMetaObject *m) +{ + // metaObjectHash didn't exist before revision 14 + if (QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && priv(m->d.data)->revision < 14) + return {}; + const auto index = priv(m->d.data)->metaObjectHashIndex; + if (index == -1) + return {}; + return stringDataView(m, index); +} + +/*! + \since 6.11 + + Returns the revisioned hash of the contents of this QMetaObject or nullptr. + + The hash has the following format $, where + hash_revision is an integer and hash_b64 is the base64 encoding of the + hash. + + Note that only hashes of the same revision should be compared. +*/ +const char *QMetaObject::metaObjectHash() const +{ + return objectMetaObjectHash(this).constData(); +} + /*! Returns the method offset for this class; i.e. the index position of this class's first member function. -- cgit v1.2.3