How to write the data from QTVector 3D into 3 Arrays (Qbytearray x; Qbytearray y;Qbytearray z;)



  • Good day

    I am having a problem understanding QTVector3D .
    Below is a snipped from the QTLabs Sensehat module for Raspberry Pi. The example works perfectly .
    I would like to send the data via Serial or UDP and therefore would like to Write the x,y,z values from QVector3D into 3 Arrays so i can send them. My problem is i don't know how i can split "v" into 3 arrays ?

    Qbytearray X;
    Qbytearray Y;
    Qbytearray Z;

    myarray.append(v); does obviously not work

    How would i do that ? I could not

    QObject::connect(&sensors, &QSenseHatSensors::gyroChanged, [](const QVector3D &v) {
        qDebug() << "Gyro:" << v;
    });
    

    Hope someone can help me


  • Moderators

    @Markus-Ippy

    QDataStream xStream(&X, QIODevice::WriteOnly);
    xStream << v.x();
    

    Same for Y and Z.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.