Comparing QVariant::Type with custom registered types
-
wrote on 24 Jul 2018, 10:20 last edited by
Hello,
I'm trying to implement a conversion function which looks like this:
CustomDataType conversionFunc(QVariant::Type type) { switch (type) { case QVariant::Int: return CustomDataType::C_INT; case QVariant::Double: return CustomDataType::C_DOUBLE; . . . default: return CustomDataType::C_INVALID; } }
This works fine if I don't use non Qt data types in QVariant. I would like to add a new case e.g.:
case QVariant::Eigen::Vector3d: return CustomDataType::C_VEC3D;
This won't build although I registered the type with
Q_DECLARE_METATYPE(Eigen::Vector3d)
. Is something like this possible? If so, how? I can still compareQVariant::typeName()
, but isn't there some way of doing this using enums like in the code above? -
wrote on 24 Jul 2018, 10:25 last edited by
-
Hello,
I'm trying to implement a conversion function which looks like this:
CustomDataType conversionFunc(QVariant::Type type) { switch (type) { case QVariant::Int: return CustomDataType::C_INT; case QVariant::Double: return CustomDataType::C_DOUBLE; . . . default: return CustomDataType::C_INVALID; } }
This works fine if I don't use non Qt data types in QVariant. I would like to add a new case e.g.:
case QVariant::Eigen::Vector3d: return CustomDataType::C_VEC3D;
This won't build although I registered the type with
Q_DECLARE_METATYPE(Eigen::Vector3d)
. Is something like this possible? If so, how? I can still compareQVariant::typeName()
, but isn't there some way of doing this using enums like in the code above?@sykac said in Comparing QVariant::Type with custom registered types:
I registered the type with Q_DECLARE_METATYPE(Eigen::Vector3d).
Why do you want to do that in the first place? What's the point of having an eigen vector in a
QVariant
? -
wrote on 24 Jul 2018, 12:43 last edited by
@kshegunov I'm using it in a generic interface - one method for passing multiple datatypes in one argument.
@VRonin Thanks, that's what I needed.
-
@kshegunov I'm using it in a generic interface - one method for passing multiple datatypes in one argument.
@VRonin Thanks, that's what I needed.
wrote on 24 Jul 2018, 13:03 last edited by@sykac said in Comparing QVariant::Type with custom registered types:
one method for passing multiple datatypes in one argument
Looks like you really want a template method instead
1/5