Important: Please read the Qt Code of Conduct -

Help using QUdpSocket in blocking mode without an event loop

  • Hi

    Having problems using qudpsocket in blocking mode

    My code is below, runs in a seperate thread

    void run()

    QUdpSocket s;


    //get data from other thread

    //code to process data

    //then send out on wire
    qint64 n;
    n = s.writeDatagram( buffer, len, QHostAddress("........."), port);
    if (len != n)
              qDebug() << "Error sending data << qPrintable(s.errorString());



    The code was originally written using bsd sockets using sendto (socket.h) in blocking mode.

    The writeDatagram function function sometimes fails with QAbstractSocket::NetworkError, however the original sendto never failed

    I suppose the bottom line is how do I make the QUdpSocket writeDatagram function work like socket.h sendto function?


  • you could try waitForBytesWritten

    "Your text to link here...":

  • Hi

    Yes, if you look at the code you will see that I have tried that. What I dont understand is a way to make writeDatagram behave like socket.h function sendto in blocking mode.

    Any help would be appreciated


Log in to reply