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 can read 0x00 from hex file?

How can read 0x00 from hex file?

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

    I read 4 bytes 4 bytes from a hex file but it does not read 0x00, for example a line is 0002EE00
    But only 02EE is read and when converted to decimal it should be 0002EE00 = 192000 but 02EE = 750 is received ,How can I fix it?

    bool ok;  QByteArray line; uint FPS, NumChannel, intsample, intband = 0;
    
    QString dataFilePath = QDir::homePath().append("/1.dat"); /
     mDataFile = new QFile(dataFilePath);
     mDataFile->open(QFile::OpenModeFlag::ReadOnly);
    
    
     do {
         line = mDataFile->read(4).data();
         if (line.toHex()== "649832fa") {
            mDataFile->seek(9);
             QByteArray sampleRate = mDataFile->read(4).data();
             qDebug()<<sampleRate.toHex();
            QString str(sampleRate.toHex());
                       intsample = str.toUInt(&ok,16);
                        qDebug()<<intsample;
           }
     } while (!line.isNull());
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @zhmh said in How can read 0x00 from hex file?:

      line = mDataFile->read(4).data();

      This is wrong. You convert a QByteArray to a char* and than back to a QByteArray for no reason with operator =(const char*) which takes \0 as string terminator (what else should it use though)

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      5

      • Login

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