QByteArray array; array.reserve(1000); //reserve memory for 1000 bytes array.append("Hello, world!"); //append a string to the array
QByteArray array("Hello, world!"); array.reserve(1000); //reserve memory for 1000 bytesIn this example, we create a QByteArray object with an initial value of "Hello, world!" and then reserve memory for 1000 bytes using the reserve() function. This would be useful if we plan to append more data to the array later and want to avoid reallocations. The QByteArray reserve() function is part of the Qt Core module.