From f69144471bd2e6a6b92f57e7727f28af9386d846 Mon Sep 17 00:00:00 2001 From: Fawzi Mohamed Date: Fri, 11 Sep 2020 15:08:26 +0200 Subject: Allow getting a const pointer out of a variant containing pointer Currently A a; QVariant::fromValue(&a).value() == nullptr; Still casting non const to const is safe, and worked in Qt5. After this change A a; QVariant::fromValue(&a).value() == &a; Change-Id: I257049d084c712b00a338a2943d379aa478e0981 Reviewed-by: Fabian Kosmale --- src/corelib/kernel/qvariant.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/corelib/kernel/qvariant.h') diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 04b93c262a..907094d25c 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -53,6 +53,7 @@ #include #endif #include +#include #if __has_include() && __cplusplus >= 201703L #include @@ -572,6 +573,12 @@ template inline T qvariant_cast(const QVariant &v) QMetaType targetType = QMetaType::fromType(); if (v.d.type() == targetType) return v.d.get(); + if constexpr (std::is_same_v> const *>) { + using nonConstT = std::remove_const_t> *; + QMetaType nonConstTargetType = QMetaType::fromType(); + if (v.d.type() == nonConstTargetType) + return v.d.get(); + } T t{}; QMetaType::convert(v.metaType(), v.constData(), targetType, &t); -- cgit v1.2.3