Summarize the conversion between QByteArray and structure in Qt, which will be more convenient in encoding and decoding.
- Structure conversion QByteArray
struct StTest
{
int iNum1;
char chNum;
int iNum2;
};
QByteArray arrTest;
StTest test;
arrTest.append((char*)&test, sizeof(StTest));
- QByteArray transfer structure
StTest pTest = (StTest )arrTest.data();