Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Warning: hasPendingDatagrams called in UnconnectedState. Huh?

    General and Desktop
    5
    5
    4624
    Loading More Posts
    • 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
      mnbv last edited by

      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 Reply Quote 0
      • C
        ChrisW67 last edited by

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

        1 Reply Last reply Reply Quote 0
        • T
          t3685 last edited by

          Did you check the return value of bind()?

          1 Reply Last reply Reply Quote 0
          • H
            houmingc last edited by

            how to check the return value of Qt bind()

            1 Reply Last reply Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              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 Reply Quote 2
              • First post
                Last post