参考:https://blog.csdn.net/qq78442761/article/details/85623507
假如有一帧数据的格式如下:
struct DATA1
{
char header1;
char header2;
uint16_t type;
uint16_t lenght;
char check1;
char check2;
friend QDebug operator << (QDebug os ,DATA1 d)
{
os <<"type: " <<d.type<< "length: " <<d.lenght;
return os;
}
};
char array[8] = {0x55,0x5a,0x01,0x32,0x31,0x08,0x01,0x02};
QByteArray bArray(array);
DATA1 *Da = (DATA1*) bArray.data();
qDebug()<<*Da;
打印输出:type: 12961 length: 2097