LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   storing numbers in QByteArray (https://www.linuxquestions.org/questions/programming-9/storing-numbers-in-qbytearray-850540/)

vendtagain 12-15-2010 09:17 PM

storing numbers in QByteArray
 
I have a program that sends QByteArray datagrams over a udp socket. I would like to have 4 bytes of the datagram that contain a 32 bit integer. When saving numbers to the QByteArray, I have tried the static function number(int) and member function setNum(int), but they convert the integer to its decimal string representation and save that in the byte array. So if the number were 10, it takes 2 bytes, if it were 10,000,000 it takes 8 bytes. This wastes space, and makes it more difficult to get the number when it is packed with a few other pieces of data in the same datagram. Is there a standard way of doing this in Qt?

graemef 12-16-2010 09:12 AM

Check out QDataStream, I believe that is the standard way of doing it?


All times are GMT -5. The time now is 12:25 PM.