elcuco
4th November 2010, 19:00
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:
// QByteArray byte_array, int start_offset, int count
QString s;
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).
s = byte_array.truncate( start_offset, count ).toLatin1();
My code currently reads:
// QByteArray byte_array, int start_offset, int count
QString s;
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).
s = byte_array.truncate( start_offset, count ).toLatin1();