Can QVariant be used with QMatrix4x4 and QVector3D etc

Viewed 178

tldr : I've noticed that QMatrix4x4 and QVector3D (and QVector2D) all have the function :

QVariant QMatrix4x4::operator QVariant() const

Is there a way to get the value of a QVariant as a QMatrix4x4 or QVector2D ?

context :

I'm making a "game engine" (this is more an attempt to learn how to do so) with Qt and OpenGL. And I'm in the process of automatically parsing Shaders to find uniforms and create a QObject class to have a signal and a slot to update the uniform that way. Since it is not possible to mix template and Q_OBJECT I thought that my uniform binder class needed to use QVariants

Thank you in advance for your precious help.

1 Answers

Assuming v a QVariant created from a QMatrix4x4, then QMatrix4x4 matrix = v.value<QMatrix4x4>(); is what you need; the same thing is valid for QVector3D, using v.value<QVector3D>();.

For more information: QVariant#value

Related