I think you want to have 1 byte alignment because you want to read from network directly into the structure. It's better to avoid lazyness and do it properly:
struct RECEIVEDATA {
unsigned short tag;
char name[10];
char id[10];
}; // assuming 22 bytes
//...
item.tag = (ba.at(0) << 8) | ba.at(1);
memcpy(item.name, ba.constData()+2, 10);
memcpy(item.id, ba.constData()+12, 10);
struct RECEIVEDATA {
unsigned short tag;
char name[10];
char id[10];
}; // assuming 22 bytes
//...
QByteArray ba = socket->read(22);
item.tag = (ba.at(0) << 8) | ba.at(1);
memcpy(item.name, ba.constData()+2, 10);
memcpy(item.id, ba.constData()+12, 10);
To copy to clipboard, switch view to plain text mode
Bookmarks