PDA

View Full Version : How to read record from .hex file to Qbyte Array



Anamika s
10th November 2020, 06:15
Hi ,

i have a use case were i have to read byte data from .hex file of size around 4093 bytes to Qbyte array.
while reading data from file i have to read only 8bytes at a time.

i am new to Qt.

how do i achieve this use case?

ChrisW67
10th November 2020, 08:08
What is a .hex file? Might be an Intel HEX (https://en.wikipedia.org/wiki/Intel_HEX) but could a be a multitude of other things.

You can slurp the whole file into memory using just QFile and QByteArray. Not sure where the 8-bytes at a time thing is coming from, but you could do that with these classes too.

If it is actual an Intel HEX file then you could read the lines using QTextStream and pull them apart with the methods in QString. Alternatively, stay at a lower level and use QByteArray and its fromHex() method.