PDA

View Full Version : How to send double or qreal to a QUdpSocket?



umz30
14th April 2009, 23:10
Hi Folks,

I need to send data of type double or qreal in its original 8 byte order to another application (on another machine) through a UDP port. Packet format and protocol on the other application can not be changed, therefore, there is no way around to that.

Here is what i tried to do and got stuck:

Created a QUdpSocket successfuly and QByteArray containing "abracadabra" was transferred to other application.

Now i have to concatenate a double precision number (not its text representation) to this QByteArray.

How do i do that??????:confused:

wysota
15th April 2009, 08:54
double dbl = 7.01;
QByteArray ba((const char*)&dbl, sizeof(dbl));

umz30
16th April 2009, 05:34
Thanks Guru. Seems like i need to remove some rust from my old C++ programming skills.:rolleyes: