QVariant to QVector3D
-
Hi,
The following should work:QVector3D vec; variant.setData(QVariant::fromValue<QVector3D>(vec)); vec=variant.value<QVector3D>();
-Michael.
-
@beecksche
Hello, that's an old post. But in 2024 there's an implicit conversion operator for QVector3D into a QVariant, thus you could write it this way:
P.S. Antispam check got wild, sorry for using a pic.
-
@beecksche
Hello, that's an old post. But in 2024 there's an implicit conversion operator for QVector3D into a QVariant, thus you could write it this way:
P.S. Antispam check got wild, sorry for using a pic.
-
qvariant_cast
is templated and is equivalent toQVariant::value
. -
@MMD18 Seems like qvariant_cast is the only solution when you don't know the type at compile time and don't want to write a template function only for this conversion.
@MMD18 said in QVariant to QVector3D:
Seems like qvariant_cast is the only solution when you don't know the type at compile time
Is it actually possible to not provide the type to
qvariant_cast
? I don't see how the compiler would deduce the return type.