diff options
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r-- | src/corelib/kernel/qvariant.h | 7 |
1 files changed, 7 insertions, 0 deletions
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 <QtCore/qbytearraylist.h> #endif #include <memory> +#include <type_traits> #if __has_include(<variant>) && __cplusplus >= 201703L #include <variant> @@ -572,6 +573,12 @@ template<typename T> inline T qvariant_cast(const QVariant &v) QMetaType targetType = QMetaType::fromType<T>(); if (v.d.type() == targetType) return v.d.get<T>(); + if constexpr (std::is_same_v<T,std::remove_const_t<std::remove_pointer_t<T>> const *>) { + using nonConstT = std::remove_const_t<std::remove_pointer_t<T>> *; + QMetaType nonConstTargetType = QMetaType::fromType<nonConstT>(); + if (v.d.type() == nonConstTargetType) + return v.d.get<nonConstT>(); + } T t{}; QMetaType::convert(v.metaType(), v.constData(), targetType, &t); |