Remove first bytes from QByteArray

You can use QByteArray::mid:

ByteArrayData = data.mid(n);
//...
ByteArrayData.append(data.mid(n));

What you seem to want is simply copy the original array and use remove;

ByteArrayData = data;
ByteArrayData.remove(0, n);            // Removes first n bytes of ByteArrayData,
                                       // leaving data unchanged

Since a QByteArray is implicitly shared, the construction of the copy takes constant time, and the modification (deletion) is what will make the actual copy when needed.

To append efficiently, you can just use data to get to the byte array, and append the part you want. That will prevent un-necessary temporary objects. That would look something like;

ByteArrayData.append(data.data() + n, data.size() - n);

Tags:

Qt

Qbytearray