Important: Please read the Qt Code of Conduct -

QUdpSocket working on Ubuntu but not WIndows10

  • Hello everyone,

    After looking through the forum, I did not see a solution to this particular problem.
    I am having trouble with sending UDP packets through to Qt on Windows10.

    For sending a UDP packet, I'm using PacketSender from
    Using this program, TCP packets are picked up by wireshark but UDP packets are not, even with the same IP address and local port.

    For the code, QUdpSocket is running on a separate thread.
    It works on Ubuntu but the same code does not work in Windows 10.
    I disabled Windows Firewall and also added a new inbound rule to unblock the local port for UDP but this doesn't seem to solve the problem.

    My Qt code for receiving the UDP packets is:

    MySocket.h :

    class MyUDPSocket: public QThread
        MyUDPSocket(moodycamel::BlockingReaderWriterQueue<QByteArray>& buffer);
        void run();
    public slots:
        void readPackets();
        QUdpSocket *udpSkt; 
        moodycamel::BlockingReaderWriterQueue<QByteArray>& queue; 


    MyUDPSocket::MyUDPSocket(moodycamel::BlockingReaderWriterQueue<QByteArray>& buffer)
        : queue(buffer)
    void MyUDPSocket::run() {
        udpSkt = new QUdpSocket(this);
        udpSkt->bind(QHostAddress::Any, 56666);
        connect(udpSkt, SIGNAL(readyRead()), this, SLOT(readPackets()));
    void MyUDPSocket::readPackets() {
        while (udpSkt->hasPendingDatagrams())  {
            QByteArray datagram;
            QHostAddress sender;
            quint16 senderPort;
            udpSkt->readDatagram(, datagram.size(), &sender, &senderPort);
            if(datagram.size() > 0) {

    Thank you for your help.

  • QThread is not the thread, it's a wrapper around the secondary thread living in the main thread. Slots of a QThread subclass are executed in the main thread.

  • Thank you for the information @VRonin
    I applied it to my implementation.

    Did anybody have a problem with porting QUdpSockets to Windows10 from Linux?

Log in to reply