Skip to content

Instantly share code, notes, and snippets.

@kisuya
Created May 10, 2017 05:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kisuya/f3094dd6efa56cecf52c3044328933d1 to your computer and use it in GitHub Desktop.
Save kisuya/f3094dd6efa56cecf52c3044328933d1 to your computer and use it in GitHub Desktop.
Qt Int to QByteArray for network packet
static inline QByteArray IntToArray(qint32 source) //Use qint32 to ensure that the number have 4 bytes
{
//Avoid use of cast, this is the Qt way to serialize objects
QByteArray temp;
QDataStream data(&temp, QIODevice::ReadWrite);
data << source;
return temp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment