Results 1 to 6 of 6

Thread: QUdpSocket High rate message reading

  1. #1
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QUdpSocket High rate message reading

    Hi, everybody!

    I have a strange issue in working with QUdpSocket and readyRead signal, I can say it's not working as I think,

    I create a QUdpSocket and bind it to some port , connect the readyRead signal to my slot and I read all the pending datagram as below

    Qt Code:
    1. if(!udp_listener)
    2. {
    3. udp_listener = new QUdpSocket(this);
    4. connect(udp_listener, SiGNAL(readyRead()), this, SLOT(readBuffers(), Qt::QueuedConnection);
    5. // the rate of receiving data is 10 msec if i dont put Qt::QueuedConnection, it didn't receive any more signal after first received. why ???
    6. // change the rate of data to 1 sec and this code work well without Qt::QueuedConnection !!!
    7. }
    8.  
    9. udp_lister.bind(Any, 5555);
    To copy to clipboard, switch view to plain text mode 

    and my readBuffers code
    Qt Code:
    1. void readBuffers() {
    2. QString buffer;
    3. while(udp_listener->hasPendingDatagrams()) {
    4. QByteArray received;
    5. received.resize(udp_listener->pendingDatagramSize());
    6. udp_listener->readDatagram(received, received.size(), 0,0);
    7. buffer.append(received);
    8. // Do some job in 1 msec on buffer and take data from buffer
    9. if(/* some works done */) buffer.clear(); // almost every time my buffer got cleared
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    I thought my problems solved with using of Qt::QueuedConnection but today I add another widget to my project and updated it every 100 msec and I don't know how but my slot didn't signaled any more after 2 seconds.

    If I change my timer interval or sending data rate to 1 sec, everything is fine.

    all of my classes and my widgets live in main program's thread and I don't use another thread, but it seems I should!
    so why signals dropped by Qt eventloop.
    I check my socket state and it did'nt change after Bound.

    Thanks in advance
    Last edited by danics; 2nd August 2016 at 12:28.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QUdpSocket High rate message reading

    That QueuedConnection looks wrong, any specific reason why you added it?

    If the QUdpSocket is in the same thread as the receiver this just adds more delay, if they are on separate threads then the socket is used from two threads without concurrency protection.

    Cheers,
    _

  3. #3
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QUdpSocket High rate message reading

    I mentioned it in my code

    // the rate of receiving data is 10 msec if i don't put Qt::QueuedConnection, it didn't receive any more signal after first one. why ???
    // change the rate of data to 1 sec and this code work well without Qt::QueuedConnection !!!

    I see this bug report do you think its related? I m using Qt 5.6 on Windows 7
    https://bugreports.qt.io/browse/QTBUG-46552
    Last edited by danics; 2nd August 2016 at 14:21.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QUdpSocket High rate message reading

    Well, that bug should be fixed in your version, but it indeed sounds similar.

    When you say your slot isn't called anymore, do you mean both slots or one specific, i.e. the data receive slot or the widget update slot?

    Is there any interaction from the data processing to the widget?

    Cheers,
    _

  5. #5
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QUdpSocket High rate message reading

    Quote Originally Posted by anda_skoa View Post
    When you say your slot isn't called anymore, do you mean both slots or one specific, i.e. the data receive slot or the widget update slot?
    No, just my socket received slot doesn't call any more, actually my widgets remained responsive and work well
    Quote Originally Posted by anda_skoa View Post
    Is there any interaction from the data processing to the widget?
    No, When data received I just update some values in my class, and my widget just read this values each 100 ms from class and fill the form and update some charts


    Added after 1 20 minutes:


    How can I find if signals queue is full or not?
    Last edited by danics; 2nd August 2016 at 19:06.

  6. #6
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QUdpSocket High rate message reading

    Hi, I was wrong about my Qt version, it was Qt 5.5 and now I updated to 5.7 and everything works great now even without QueuedConnection and with default connection. thanks

Similar Threads

  1. BroadCast message from Linux to windows using QUDPsocket
    By arunkumaraymuo in forum Qt Programming
    Replies: 1
    Last Post: 25th April 2015, 19:55
  2. Blink LED for 5 seconds with 1Hz rate
    By sammey_geek in forum Newbie
    Replies: 4
    Last Post: 21st September 2013, 12:57
  3. Replies: 2
    Last Post: 23rd April 2013, 18:34
  4. baud rate
    By adriana in forum Newbie
    Replies: 5
    Last Post: 6th May 2011, 17:18
  5. High performance large file reading on OSX
    By mikeee7 in forum Qt Programming
    Replies: 2
    Last Post: 15th October 2009, 14:18

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
  •  
Qt is a trademark of The Qt Company.