QByteArray::QByteArray(const char *data, int size)
will copy the data.
QByteArray::fromRawData(const char *data, int size)
will use the already existing data.
Depending on your implementation, not copying the data might end up being problematic.
After you have the data in a byte array, there are several ways to go, you can directly construct a buffer:
QBuffer(QByteArray *byteArray, QObject *parent = Q_NULLPTR)
or more likely, since you are playing audio, you might want to reusing the same buffer and use one of the following to refill it:
setBuffer(QByteArray *byteArray)
setData(const QByteArray &data)
Lastly, there is also void QBuffer::setData(const char *data, int size)
for which you don't even need the byte array step at all.
Lastly, remember that QBuffer
is an IO device - it needs to be opened in order for it to work. A quick test shows that it works as expected:
char data[] = {1, 2, 3};
void * vdata = data;
QBuffer buffer;
buffer.setData((char *)vdata, sizeof(data));
buffer.open(QIODevice::ReadOnly);
qDebug() << buffer.readAll(); // outputs "\x01\x02\x03"