Convert from float to QByteArray

Posted by radix07 on Stack Overflow See other posts from Stack Overflow or by radix07
Published on 2010-05-05T14:16:48Z Indexed on 2010/05/05 14:18 UTC
Read the original article Hit count: 209

Filed under:
|
|

Is there a quick way to convert a float value to a byte wise (hex) representation in a QByteArray?

Have done similar with memcpy() before using arrays, but this doesn't seem to work too well with QByteArray.

For example:

memcpy(&byteArrayData,&floatData,sizeof(float));

Can go the other way just fine using:

float *value= (float *)byteArrayData.data();

Am I just implementing this wrong or is there a better way to do it using Qt?

Thanks

© Stack Overflow or respective owner

Related posts about qt

Related posts about c++