PDA

View Full Version : How to read the Binary data from QFile to buffer of type BYTE*???



Gokulnathvc
9th March 2011, 08:19
How to read the Binary data from QFile to buffer of type BYTE*???

ChrisW67
9th March 2011, 08:25
I assume that BYTE is some typedef or macro that is equivalent to char.

QByteArray and QIODevice::readAll(). You can access the bytes through QByteArray::data().

Gokulnathvc
9th March 2011, 09:40
How to convert QByteArrray to BYTE*???

Gokulnathvc
9th March 2011, 09:40
How to convert QByteArrray to BYTE*???

stampede
9th March 2011, 10:04
For me it looks like you expect that we're gonna solve all your issues for you - a while ago you've posted the same question here: link to thread (http://www.qtcentre.org/threads/39475-How-to-read-the-Binary-data-from-QFile-to-buffer-of-type-BYTE*)
Please, can you kindly tell us what have you tried so far ? Because it looks like you are saying "I don't want help, I want a solution".


===
Note: I merged the threads, so this message was originally a response to the post while it was at a different place! (Lykurg)

Gokulnathvc
9th March 2011, 11:28
While reading the same file for the second time.. It returns null in the buffer..
I am using the following code::

QByteArray buf;
buf=file.readAll();

The above code is inside the while loop. If it enters for the second time.. buf value becomes null. Pls help me...

squidge
9th March 2011, 12:19
So what you are trying to do is read the entire contents of the file more than once?

Gokulnathvc
10th March 2011, 04:29
Yes.. That is the case

Lykurg
10th March 2011, 05:53
Well, then it is nonsense. Simply do something like:
buf += buf;. If you still want to read the file again, use QIODevice::reset().

Gokulnathvc
10th March 2011, 06:44
How to pass char * data to Byte* in QT??

Gokulnathvc
10th March 2011, 07:14
How to read the full contents of the File 'n' times in QT??

Added after 19 minutes:

I am getting the values till the last loop runs. After that nothing is present in the buffer.

Am using the following code:
int pos1=file.pos();
buf=file.read(size);
int pos2=file.pos();
strcpy(buffer,buf.data());

PLS HELP ME..

ChrisW67
10th March 2011, 07:26
Stop asking the same question over and over - it rapidly annoys people who might be inclined to help.

You already have the answer to this in
http://www.qtcentre.org/threads/39475-How-to-read-the-Binary-data-from-QFile-to-buffer-of-type-BYTE*?highlight=

ChrisW67
10th March 2011, 07:27
As I mentioned earlier, a Byte (or is that BYTE) is usually typedef or macro for a "char" on every platform I have handy. So a BYTE* or Byte* is a char*. Equating these two has nothing to do with Qt, it is straight C++.

Lykurg
10th March 2011, 07:35
So, the order of responses gets a little messy here because I merged the thread. But we really do not need 4 (in letters: four) threads on that topic.