QByteArray data = "This is an example QByteArray"; QByteArray subdata = data.mid(8, 7);
char c[] = {'B', 'y', 't', 'e', 's'}; QByteArray ba(c, 5); QByteArray subba = ba.mid(2);In this example, we create a char array with the content "Bytes". We use this array to create a new QByteArray with a length of 5. Then we create a new subarray starting from position 2 (which is the letter 't') until the end of the array. This results in a new QByteArray containing "tes". The package library for this code is "QtCore" in Qt.