Results 1 to 5 of 5

Thread: Waiting for new values sent by UDP in Qt

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2016
    Posts
    2
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Smile Waiting for new values sent by UDP in Qt

    Hi guys!
    I have quite easy, I guess ^^, problem with modification of my code. In general it reads incomming messeges (UDP) and print them in cmd. Instead of reading them all the time, I would like to modify it to wait for new value and then display. Thanks in advance for any help!

    Code:
    Qt Code:
    1. #include "myudp.h"
    2.  
    3. MyUDP::MyUDP(QObject *parent) :
    4. QObject(parent)
    5. {
    6. socket = new QUdpSocket(this);
    7. socket->bind(QHostAddress::LocalHost, 25000);
    8. connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
    9. }
    10.  
    11. void MyUDP::readyRead()
    12. {
    13. double a[3];
    14. double prev_a[3];
    15.  
    16. QByteArray buffer;
    17. buffer.resize(socket->pendingDatagramSize());
    18.  
    19. QHostAddress sender;
    20. quint16 senderPort;
    21.  
    22. socket->readDatagram(buffer.data(), buffer.size(),
    23. &sender, &senderPort);
    24.  
    25. if(a[0] != prev_a[0] || a[1] != prev_a[1] || a[2] != prev_a[2])
    26. {
    27. memcpy(&a, buffer, 3*sizeof(double));
    28. qDebug() << "\nMessage from: " << sender.toString();
    29. qDebug() << "Message port: " << senderPort;
    30. qDebug() << "X:" << a[0];
    31. qDebug() << "Y:" << a[1];
    32. qDebug() << "V:" << a[2];
    33. }
    34. prev_a[0] = a[0];
    35. prev_a[1] = a[1];
    36. prev_a[2] = a[2];
    37.  
    38. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 25th May 2016 at 11:02. Reason: missing [code] tags

Similar Threads

  1. Replies: 5
    Last Post: 27th November 2014, 10:15
  2. How to convert string hex values to its real binary values?
    By AttilaPethe in forum Qt Programming
    Replies: 1
    Last Post: 20th February 2012, 22:47
  3. Waiting WebKit
    By giusepped in forum Qt Programming
    Replies: 0
    Last Post: 13th May 2009, 03:40
  4. Waiting on a thread?
    By MrGarbage in forum Qt Programming
    Replies: 1
    Last Post: 3rd November 2007, 16:13
  5. Waiting for something
    By JonathanForQT4 in forum Newbie
    Replies: 20
    Last Post: 2nd May 2007, 17:35

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.