Is there a correct/good way to convert QGyroscopeReading to QVector3D in Qt5?
QGyroscopeReading has its x,y and z values stored as qreal, while QVector3D uses float.
Since qreal is not guaranteed to be float (it's type is specified at Qt build time), the warning-free naive conversion looks really ugly:
QGyroscopeReading gr;
QVector3D myVec(static_cast<float>(gr.x())
, static_cast<float>(gr.y())
, static_cast<float>(gr.z()));
Surely there is something better?
From Qt doc. QGyroscopeReading Class:
So, conversion of
qrealtofloatis your least problem except you just want to store the values in aQVector3D(remembering that this doesn't represent a point or vector in 3D space). But if this is the case, then your conversion is fine. (Although, I don't understand why not to store gyroscope reading just asQGyroscopeReading.)If you want to apply
QGyroscodeReadingto aQVector3D(e.g. to display the effect), then you could apply the rotations to a predefined vector (e.g.QVector3D(0, 0, 1)). For a cumulate update, the time would be necessary as well (to convert angular velocities to angles).For the time, the
QGyroscopeReading::timestamp()could be interesting (i.e. determine duration from current timestamp and the previous one). Though, the doc. is not very encouraging: