PDA

View Full Version : Store data in bits & Bytes



2lights
9th September 2013, 08:55
Good Day,

I have a text file that needs to be read into the program, must be modified
& then when the data is stored again it needs to be stored in a new certain format

Example
Field Name | Size
A | 2 bytes
B | 4 bytes
C | 12 bits
D | 1 byte
& so on...

When I read data into program its stored in various arrays
of type QPoint, QList<int>, QList<double> and so on

I just need to know
Does Qt support what I need to store data accordingly
& if so,
How would I go about it


Kind Regards

Help much appreciated :)
Example will be glady accepted

ChrisW67
9th September 2013, 10:34
How do you intend to save a 12-bit field in a file of whole bytes? You can write any bytes you want to a QFile but nothing here has anything specifically to do with Qt.

2lights
9th September 2013, 10:54
Was reading up on "Serializing Qt Data Types"
http://harmattan-dev.nokia.com/docs/platform-api-reference/xml/daily-docs/libqt4/datastreamformat.html

I understand the concepts just not sure how to go about storing data in relevant variable size?

My project from among other things is to store data in defined field size
Using a qt interface to interact with use manipulate data
and then store data accordingly

how does qt store its data when variables are written to a file?
How do I control the size of the fields within this field?

Also How do I write qt data variables to file in BINARY FORMAT
please help

12bits binary format How

Please direct me in the right direction

anda_skoa
9th September 2013, 13:39
QFile is a QIODevice subclass. QIODevice has low level read and write methods that write byte arrays (C style char* or Qt/C++ QByteArray).

This has nothing to do with QDataStream, that class is for serializing data types in a Qt specific format. Your data format is different so you obviously need to write the "parsing" and "formatting" code into bytes yourself.

Cheers,
_