View Full Version : QByteArray
gyre
9th October 2007, 11:06
Hi all!
I created QByteArray dynamically- QByteArray(NULL, BUFFER_SIZE) I want it to do this:
I want "N" bytes of some "DATA" to be copied to this QByteArray. So something like memcpy function does. Is there any method like this ? I was lookig for it but no success :( I can do that in for cycle but that's not good :(
Is there any other function I could use for doing this ?
Thanks :)
marcel
9th October 2007, 11:15
See QByteArray::append(const char*) or QByteArray::data ( the non-const version).
With the latter you could use memcpy, but you'll have to allocate it first( I think, it is not tested). The first one is safer, just appends the buffer.
wysota
9th October 2007, 11:17
See QByteArray::data() for a pointer to the data buffer and QBuffer for a QIODevice interface to the byte array. You can use either way to fill the byte array.
gyre
9th October 2007, 18:09
Well, Wysota's ideas are very close to what I want.
The thing is that I already have data in my own data buffer:
const char* data.
and I want only : int buffer_size number of these data to be copied to my
QByteArray
data() return a pointer to the data stored in QByteArray that I know.
BUT how to COPY data into it ?? Append add all data in buffer...I need only "buffer_size" bytes.
Thanks
marcel
9th October 2007, 18:30
Oh, then you might want to try:
QByteArray::QByteArray ( const char * data, int size )
Constructs a byte array containing the first size bytes of array data.
If data is 0, a null byte array is constructed.
QByteArray makes a deep copy of the string data.
But this way you can only copy the first size bytes.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.