Created
May 10, 2017 05:04
-
-
Save kisuya/f3094dd6efa56cecf52c3044328933d1 to your computer and use it in GitHub Desktop.
Qt Int to QByteArray for network packet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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