QT默认是4字节对界,所以程序中使用sizeof()时会出现问题,看采用如下方法:
/字节对齐,否则共用体那里指针处理时有问题
#pragma pack(push) //保存对齐
#pragma pack(1) //设定为1字节对齐
typedef struct{
uint16_t VoltPos; //+总电压(3位整数,1位小数)(采样)
uint16_t VoltNeg; //-总电压
int16_t DisAndChgCurrPos;
int16_t DisAndChgCurrNeg;
union BAT_SYS_STA BattCheckSta;
union BAT_SYS_STA BattAlarmSta;
uint32_t BattPackCommErrChk;
uint32_t BattPackCommErrAlm;
}BMS_SYS_DAT;
#pragma pack(pop) //恢复对齐状态
标签:字节,SYS,pragma,对齐,QT,对界
From: https://www.cnblogs.com/xihong2014/p/17010495.html