Replacing QVariant::type() when moving to Qt 6
Solved
General and Desktop
-
Hi @Perdrix,
The short version: I would just use QVariant::userType().
Longer version:
The Qt6 cast should work fine, but the Qt5 version is still using the deprecated
QVariant::Type
. As per the QVariant::type() documentation:the return value should be interpreted as
QMetaType::Type
.So it should probably be more like:
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) switch (static_cast<QMetaType::Type>(value.typeId())) #else switch (static_cast<QMetaType::Type>(value.type())) #endif
However, once you're (correctly) casting both to
QMetaType::Type
, you could just use QVariant::userType() instead, since its the same signature on Qt5 and Qt6, eg:switch (static_cast<QMetaType::Type>(value.userType()))
Cheers.