Maybe just use QIODevice::readAll()?

It will allocate the buffer as needed, so its length will be exactly the size of its content.

Cheers,
_