You copy the data representation of the class QByteArray to long. You can not know how it is implemented (unless you look into source code) and you can not handle the problem of possible changes to QByteArray implementation in later releases.
You also dont know wheter QByteArraycontains enough bytes to read from. You should check that in extract():
sizeof(*number) <= buffer.size()
sizeof(*number) <= buffer.size()
To copy to clipboard, switch view to plain text mode
Now what you really might have wanted was copying the data contained in QByteArray. Right?
Then you might either copy the bytes by yourself, using byte[]. Here some untested code for that:
for (int i = 0; i < buffer.size(); ++i)
{
(char*)number[i] = buffer[i];
}
for (int i = 0; i < buffer.size(); ++i)
{
(char*)number[i] = buffer[i];
}
To copy to clipboard, switch view to plain text mode
Or you convert QByteArray into normal C-Array and use that with memcpy:
memcpy(number,buffer.data(),sizeof(*number));
memcpy(number,buffer.data(),sizeof(*number));
To copy to clipboard, switch view to plain text mode
Bookmarks