How can read 0x00 from hex file?
Solved
General and Desktop
-
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());
-
@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)