Results 1 to 3 of 3

Thread: How to send double or qreal to a QUdpSocket?

  1. #1
    Join Date
    Apr 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question How to send double or qreal to a QUdpSocket?

    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??????

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to send double or qreal to a QUdpSocket?

    Qt Code:
    1. double dbl = 7.01;
    2. QByteArray ba((const char*)&dbl, sizeof(dbl));
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Solved

    Thanks Guru. Seems like i need to remove some rust from my old C++ programming skills.

Similar Threads

  1. Strange problems with QUdpSocket
    By montylee in forum Qt Programming
    Replies: 2
    Last Post: 14th October 2008, 07:51

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.