This doesn't do what you want.
uint8_t* x = new uint8_t;
x[0] = static_cast<uint8_t>(testWav.readAll()[0]);
This way you copy only [0] element of array. The rest of allocated memory stay uninitialized
This cannot work at all:
uint8_t* x = new uint8_t;
*x = static_cast<uint8_t>(*testWav.readAll());
QByteArray
is a class-type of dynamic container, so you can't use static_cast
to access its data as an array, it's a principally different, incompatible data structure. And you're still assigning only the first element: *x
is an equivalent of x[0]
.
QByteArray
has method QByteArray::data()
which returns a pointer to char*
:
https://doc.qt.io/qt-6/qbytearray.html#data
The pointer returned by data()
isn't owning one and points to memory allocated by class, so data contained in QByteArray
which returned by readAll()
will cease to exist at end of statement containing it, unless it's assigned to a more persistent storage:
QByteArray fileContent = file.readAll();
char *buffer = fileContent.data();
Result of fileContent.size()
would give the actual size of buffer. Note that in some cases it's more convenient to work with QByteArray instead of a raw pointer. You need conversion ONLY if you have to use some API taking raw pointer or face some performance issues.