Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Convert QByteArray to QVector<qreal>
Forum Updated to NodeBB v4.3 + New Features

Convert QByteArray to QVector<qreal>

Scheduled Pinned Locked Moved Unsolved General and Desktop
qbytearrayqvectorconvertqreal
2 Posts 2 Posters 5.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MoldyM Offline
    MoldyM Offline
    Moldy
    wrote on last edited by Moldy
    #1

    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.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      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

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved