#include <QCoreApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QByteArray buff;
float ff = 1.234f, f2;
int ii = 345,i2;
// int len = sizeof(int) + sizeof(float);
// buff.resize(8);
// qDebug()<< "size=" << buff.size();
buff.append(reinterpret_cast<const char*>(&ii),sizeof(ii));
buff.append(reinterpret_cast<const char*>(&ff),sizeof(ff));
// i2 = *reinterpret_cast<const int*>(buff.data());
// f2 = *reinterpret_cast<const float*>(buff.data()+sizeof(int));
// qDebug() << len << " " << buff.size() << " " << ii << " " << i2 << " " << ff <<" " << f2;
i2 = *reinterpret_cast<const int*>(buff.data());
f2 = *reinterpret_cast<const float*>(buff.data()+sizeof(ii));
qDebug() << buff.size() << " " << ii << " " << i2 << " " << ff <<" " << f2;
return a.exec();
}标签:cast,int,float,reinterpret,互转,sizeof,buff From: https://www.cnblogs.com/xihong2014/p/17063269.html