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. [SOLVED] QUdpSocket readyRead() signal
Qt 6.11 is out! See what's new in the release blog

[SOLVED] QUdpSocket readyRead() signal

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 10.3k Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Im having troubles seeing the readyRead() signal from a bound UDP socket. This is our current code -

    The socket is created in our class constructor -
    @
    // create the actual socket
    m_socket = new QUdpSocket(this);

    // connect activity signal for socket
    connect(m_socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
    @

    We then ask our Acquisition class to "start" acquiring some data -

    @
    bool Acquisition::start()
    {
    bool ret = true;

    if (m_socket->bind(5000, QUdpSocket::ShareAddress))
    {
        qDebug() << "Startup... " << m_socket->localAddress().toString() << m_socket->localPort();
        connect(m_socket, SIGNAL(readyRead(void)), this, SLOT(dataReady(void)));
    }
    else
    {
        qDebug() << qt_error_string();
        ret = false;
    }
    
    return ret;
    

    }
    @

    Slots -
    @
    void Acquisition::dataReady()
    {
    // dummy variables
    QHostAddress host;
    quint16 port;

    qDebug() << "dataReady";
    

    // there is some valid data available from UDP
    // keep reading until empty (same block size as sent)
    while (m_socket->hasPendingDatagrams())
    {
    // write to our UDP circular buffer
    m_socket->readDatagram((char*)m_udpbuffer.Write(), m_msgSize, &host, &port);
    }
    }
    void Acquisition::socketStateChanged(QAbstractSocket::SocketState socketState)
    {
    qDebug() << "socketStateChanged - " << socketState;
    }

    @

    When debugging our code, we hit our socketStateCahnged slot, but we never hit our dataReady slot... We have confirmed with wireshark the fact that there is some data between the devices on the specified port...

    UI Elements work as expected (signal/slots) so the mechanism behind all that seems to be ok...

    Can anyone suggest what else I am missing?

    Ubuntu 12.10 (64-bit)
    Qt - 5.0.2
    Using Qt Creator to build and debug - 2.7.0

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      socketStateChanged displays
      @socketStateChanged - QAbstractSocket::BoundState @

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Result is the same whether run from debugger, or from command line.

        When using QUdpSocket, does the application need elevated privileges? (sudo)

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          For what its worth each datagram is received as expected when writing a winsock2 application (from a Win7_64bit machine)...

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

            Does your start() routine print that bind() was successful?
            Have you tried the bind() using the default BindMode?
            Have you tried the bind() call that takes an explicit host address?

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              yes, bind() is successful (and a signal is fired to indicate the socket changed state to bound)...

              I have tried binding to an explicit host address, as well as QHostAddress::Any.
              I have tried QUdpSocket::ShareAddress and QUdpSocket::DontShareAddress.
              I have have tried wired and wireless adapters.

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                Ok, found my problem.

                The object I was using to control my acquisition was allocated on the stack, and was deleted before my QApplication.exec() routine was called... ie - I have no Udp class running!

                1 Reply Last reply
                0

                • Login

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