[Qt-interest] Binary & ASCII in QByteArray

Andre Somers andre at familiesomers.nl
Tue Aug 3 10:41:44 CEST 2010


Op Di, 3 augustus, 2010 9:58 am, schreef Paul England:
> Hi
>
> I'm not very familiar with parsing binary data, other than casting
> something that I'm expecting.
>
> I've got a file from a program that has Binary & ASCII values in it.
> I've taken a look at hexdump and I have a rough idea of what it looks
> like, but other than that, kind of stumped.  I can read it in to a
> QByteArray() but after that, I'm a bit lost on what I should do.
> Obviously "messing around" to find out how many bytes to read in at a
> time is the way to go.  Hoping to find some pointers (or maybe some
> tricks unique to QByteArray) before that endeavor.

First and foremost, you need to have a good understanding of the structure
of the file you are trying to read. As long as you don't know, you will
not be able to read it in in any meaningful or safe way. Try googling for
a description, contacting the author of the format, reverse engineering
the source of the application that made the file or just solve the puzzel
yourself by changing things in the program that creates the files and
seeing what changes in the file, but you really need to get to a
specification of the format.

Having said that, I think you should familarize yourself with QDataStream.
You can use it's stream operators to read in data from a binairy file into
variables.

André





More information about the Qt-interest-old mailing list