Problem fixed!
The image data has to be written into the buffer returned by the QImage::bits() method.
Here's the solution:
auto sz = img.byteCount();
uchar* a = new uchar[sz];
memcpy(a, img.bits(), sz);
m_lastFrame = QImage(imgSize.width(), imgSize.height(), imgFormat);
memcpy(m_lastFrame.bits(), a, sz); // We write the image data into the new QImage
delete[] a;
And with a QDataStream:
QByteArray arr;
QDataStream ds(&arr, QIODevice::ReadWrite);
ds.writeRawData((const char*)img.bits(), img.byteCount());
ds.device()->seek(0);
m_lastFrame = QImage(imgSize.width(), imgSize.height(), imgFormat);
ds.readRawData((char*)m_lastFrame.bits(), img.byteCount()); // We read the data directly into the image buffer
Thank you so much for your help JKSH an koahnig!!