diff --git a/src/core/qgsvariantutils.cpp b/src/core/qgsvariantutils.cpp index 375a6884b2a..5cf1091bb21 100644 --- a/src/core/qgsvariantutils.cpp +++ b/src/core/qgsvariantutils.cpp @@ -594,3 +594,13 @@ QVariant::Type QgsVariantUtils::metaTypeToVariantType( QMetaType::Type metaType // NOLINTEND(bugprone-branch-clone) return QVariant::Type::UserType; } + +QVariant QgsVariantUtils::createVariant( QMetaType::Type metaType ) +{ +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + return QgsVariantUtils::metaTypeToVariantType( metaType ); +#else + return QVariant( QMetaType( metaType ) ); +#endif + +} diff --git a/src/core/qgsvariantutils.h b/src/core/qgsvariantutils.h index af91da7ea1e..862d157a8ec 100644 --- a/src/core/qgsvariantutils.h +++ b/src/core/qgsvariantutils.h @@ -70,6 +70,14 @@ class CORE_EXPORT QgsVariantUtils */ static QVariant::Type metaTypeToVariantType( QMetaType::Type metaType ) SIP_SKIP; + + /** + * Helper method to properly create a QVariant from a \a metaType + * Returns the created QVariant + * TODO QGIS 4 remove this method + */ + static QVariant createVariant( QMetaType::Type metaType ) SIP_SKIP; + }; #endif // QGSVARIANTUTILS_H