Qt World Summit: Register Today!

Convert QByteArray to QVector<qreal>

  • I converted a qvector<qreal> to a QByteArray.

    I did this by: QByteArray bytesArray ((const char *) someVector.constData(), someLength * 8);

    I need to be able to reverse this and get a qvector<qreal> out of the qbytearray.

    If additional information is need, let me know.

    Some help would be very appreciated.

  • that is wrong way of doing it

    try this:

    QByteArray bytesArray
    QDataStream out(&bytesArray ,QIODevice::WriteOnly);
    out << someVector; //saves it
    QDataStream in(bytesArray);
    QVector<qreal> otherVector;
    in >> otherVector; //load

    Please note that qreal is only 99.9% safe when saving to stream and sending it around to programs built with other versions of Qt. use QVector<double> instead