diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-02-19 18:47:11 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-02-26 09:10:31 +0100 |
commit | 9d6ba110e8f98463d136fa97993db6d1968479c1 (patch) | |
tree | 501110a06ff6310d78fc0d176804c3a5af12d888 /src | |
parent | 50e857a9cbb2d41a85e85e1c10e18bd761569b88 (diff) |
QMetaType: Store QMetaObject for pointer to const QObject, too
Before this change, the QMetaType for T const* where T is derived from
QObject would not store the static QMetaObject of T. This commit changes
this. As a consequence, the metatype system can now convert between
const and non-const pointers to QObject. Note that this allows casting
const away; but so does C++ with const_cast.
In addition, a new flag, QMetaType::IsImmutable is introduced, and used
to tag the metatypes of pointer to const types. This allows code to
discern between pointers to mutable and const QObjects, which is
relevant for the QML engine.
Task-number: QTBUG-82354
Change-Id: I3e4e4f39f565bd99a65e161528ce5304df73d6d6
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/kernel/qmetatype.cpp | 1 | ||||
-rw-r--r-- | src/corelib/kernel/qmetatype.h | 3 |
2 files changed, 4 insertions, 0 deletions
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index bb4090129f..ac792a2f27 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -422,6 +422,7 @@ Q_GLOBAL_STATIC(QMetaTypeCustomRegistry, customTypeRegistry) \omitvalue IsGadget \omit This type is a Q_GADGET and it's corresponding QMetaObject can be accessed with QMetaType::metaObject Since 5.5. \endomit \omitvalue PointerToGadget \omitvalue IsQmlList + \value IsConst Indicates that values of this types are immutable; for instance because they are pointers to const objects. */ /*! diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index c1567a7990..bdea0b2879 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -398,6 +398,7 @@ public: PointerToGadget = 0x400, IsPointer = 0x800, IsQmlList =0x1000, // used in the QML engine to recognize QQmlListProperty<T> and list<T> + IsConst = 0x2000, }; Q_DECLARE_FLAGS(TypeFlags, TypeFlag) @@ -827,6 +828,7 @@ namespace QtPrivate #ifndef QT_NO_QOBJECT static yes_type checkType(QObject* ); + static yes_type checkType(const QObject* ); #endif static no_type checkType(...); static_assert(sizeof(T), "Type argument of Q_PROPERTY or Q_DECLARE_METATYPE(T*) must be fully defined"); @@ -1157,6 +1159,7 @@ namespace QtPrivate { | (QTypeInfo<T>::isPointer ? QMetaType::IsPointer : 0) | (IsUnsignedEnum<T> ? QMetaType::IsUnsignedEnumeration : 0) | (IsQmlListType<T> ? QMetaType::IsQmlList : 0) + | (std::is_const_v<std::remove_pointer_t<T>> ? QMetaType::IsConst : 0) }; }; |