View Full Version : Binary file Reading.........
umulingu
16th July 2009, 12:53
Hai
I have a binary file I want to read that
either I have to use QBitArray or ByteArray ... DataStream
pl help me
yogeshgokul
16th July 2009, 13:06
If you want to access data bit by bit. For various binary operations. You should use QBitArray.
Otherwise QByteArray and QDataStream will work.
umulingu
17th July 2009, 06:06
Hai
that binary file in LittleEndian format
what to do?
pl give some example..
yogeshgokul
17th July 2009, 06:51
Hai
that binary file in LittleEndian format
The QDataStream class provides serialization of binary data to a QIODevice.
A data stream is a binary stream of encoded information which is 100% independent of the host computer's operating system, CPU or byte order
pl give some example..
QFile file("file.dat");
file.open(QIODevice::ReadOnly);
QDataStream in(&file); // read the data serialized from the file
QString str;
qint32 a;
in >> str >> a; // extract "the answer is" and 42
umulingu
17th July 2009, 10:12
hai
i tried with QDataStream and QByteArray. but the data is empty...
QFile fileA("/home/suresh/file1.lnd");
QByteArray buffer;
if(! fileA.open(QIODevice::ReadOnly))
{
QMessageBox::information(this,tr("Unable to Open"),fileA.errorString());
return;
}
buffer=fileA.readAll();
qDebug()<<buffer.data();
qDebug()<<buffer.size();
output
206368
nish
17th July 2009, 10:45
dont use buffer.data() in qDebug... just use buffer... because a zero may terminate the char* at any point..
yogeshgokul
17th July 2009, 10:47
qDebug()<<buffer.data();
qDebug()<<buffer.size();
output
206368
The data is in the buffer, its just not printed by qDebug. You can write this buffer in another file and see. Both files should be identical.
umulingu
17th July 2009, 11:03
Hai
thanks for ur reply
actually that is binary file .
I want to read the data
how to get the datas?
nish
17th July 2009, 11:06
every binary file has a format... do you have the format (struct etc)..?
umulingu
17th July 2009, 11:25
yes I have that program and format
nish
17th July 2009, 11:30
then just go simple.. nad read the data as it was written in that program..
it must be written as
FILE* fp
fwrite(struct* ,fp);
so read it that way only..
FILE* fp
fread();...
umulingu
20th July 2009, 07:18
Thanks to all
I got solution.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.