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. QDatastream read raw data
Qt 6.11 is out! See what's new in the release blog

QDatastream read raw data

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 2.0k Views
  • 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.
  • saitejS Offline
    saitejS Offline
    saitej
    wrote on last edited by
    #1

    I have used QDatastream to write Qbytearray to a file using writerawdata().

    I tried reading this same file using QDatastream. I wanted to use readrawdata() but I dont know its length. So what is the other way to read the data again in to a qbytearray?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kuzulis
      Qt Champions 2020
      wrote on last edited by kuzulis
      #2

      There are two ways:

      1. Just use << / >> with QByteArray directly:
      QByteArray to = ...
      out << to;
      
      QByteArray from;
      in >> from;
      
      1. Or use writerawdata/readrawdata and store the array size, like:
      QByteArray to = ...
      out << qint64(to.size());
      out.writerawdata(..., size);
      
      QByteArray from;
      qint64 size = 0;
      in >> size;
      in.readrawdata(..., size);
      

      PS: I prefer the first way, if there no any restrictions/requirements for the file format.

      1 Reply Last reply
      0

      • Login

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