PDA

View Full Version : Get QByteArray from QString



Coder5546
21st December 2012, 14:57
Hi all

Look at this code



QString cmd = "some strings here";
long buffer = 2048;
QByteArray array;

I want get first 2048 byte from QString cmd to array in Utf8. Dont know how. Any suggestions?
And when i got first 2048 byte, how to take next bytes.
In QFile is simple



QFile file("file");
QByteArray array = file.read(buffer);
file.seek(buffer);
array = file.read(buffer);

Ty for any help.

anda_skoa
21st December 2012, 18:03
I want get first 2048 byte from QString cmd to array in Utf8. Dont know how. Any suggestions?




QByteArray array = cmd.toUtf8();

QByteArray first2048Bytes = array.mid( 0, 2048 );
QByteArray second2048Bytes = array.mid( 2048, 2048 );




And when i got first 2048 byte, how to take next bytes.




QByteArray second2048Bytes = array.mid( 2048, 2048 );




In QFile is simple


You can alternatively put array into a QBuffer and use that like the file.

Cheers,
_