Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Warning: hasPendingDatagrams called in UnconnectedState. Huh?

Warning: hasPendingDatagrams called in UnconnectedState. Huh?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 5 Posters 5.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mnbv
    wrote on last edited by
    #1

    Qt 4.8.0 on Windows.

    I am attempting to read data with a QUdpSocket. The socket has been bound to a port with bind(). When I attempt to read datagrams in a loop, e.g.:

    @ while (socket_.hasPendingDatagrams())
    socket_.readDatagram(data, sizeof(data));
    @

    No datagrams are read (despite Wireshark showing data arriving with a correct destination port) and the console displays:

    @QNativeSocketEngine::hasPendingDatagrams() was called in QAbstractSocket::UnconnectedState
    @

    Obviously hasPendingDatagrams() is called in UnconnectedState -- it's a UDP socket. It's never connected.

    Additionally, when I try using the event loop instead, readyRead() is never emitted.

    Using Winsock directly, I have no issues. I do not want to do that. Nothing about that console message makes sense, and everything I've done is 100% as per the documentation. How do I convince Qt that UDP sockets are supposed to be in UnconnectedState, and actually receive data on the socket? As it stands I have not been able to successfully use a QUdpSocket to perform the seemingly simple task of receiving data.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      Have you bound the QUdpSocket to a port with QUdpSocket::bind()?

      1 Reply Last reply
      0
      • T Offline
        T Offline
        t3685
        wrote on last edited by
        #3

        Did you check the return value of bind()?

        1 Reply Last reply
        0
        • H Offline
          H Offline
          houmingc
          wrote on last edited by
          #4

          how to check the return value of Qt bind()

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Please, look at the function documentation. It returns a boolean value.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved