Part of a QByteArray() to QString()
In my situation I have a QByteArray which I get from a UDP socket. I know that from bytes 10 I have up to 5 bytes which represent some name (guaranteed to be latin1).
My code currently reads:
Code:
// QByteArray byte_array, int start_offset, int count
for ( int i=0; i<count; i ++ )
s.append( byte_array[ start_offset + i ] );
I was wondering if there is a better way. Something like this code (I would assume it would check boundaries and it will use less memory cause of less copies).
Code:
s = byte_array.truncate( start_offset, count ).toLatin1();
Re: Part of a QByteArray() to QString()
Not truncate, but mid:
Code:
s
= QString::fromLatin1(byte_array.
mid(10,
5));
The QByteArray doc is a great place to look for answers :rolleyes: