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. How to read .bin file and then split the QByteArray for the different variables

How to read .bin file and then split the QByteArray for the different variables

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 775 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.
  • H Offline
    H Offline
    hashtagNoob
    wrote on last edited by
    #1

    Hi,

    Let's say I have @class Person
    {
    private:
    QString name;
    int age;
    double smthng;
    public:
    writeData(QFile&);
    readData(QFile&);
    };@

    First for writing the data in the file I converted all variables to QByteArray and used QFile::write();

    Now I want to read the file but how am I suppost to take the different variables? If I use readall(); I will have one QByteArray but how to split it to know which byte for which variable is? Should I use sizeof or something like that?

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hashtagNoob
      wrote on last edited by
      #2

      Ok here is what I did for a solution.

      Since I have several QStrings I made one big QString that appends all small QStrings and between them there is a special sign (for example '$'). All the numbers I converted to QString also with QString::number().

      All the information is in one big QString so when I load it and use QFile::readAll() and then QByteArray::toHex and then QByteArray::toLatin1() I will have my big QString that I know how it's made.

      I will test now hope this plan works.

      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