Important: Please read the Qt Code of Conduct -

QT Udp socket

  • QObject::connect: No such signal QUdpSocket::Read

    I get an error.

    MainWindow.h looks like this...........................................

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QUdpSocket>

    namespace Ui { class MainWindow; }

    class MainWindow : public QMainWindow

    MainWindow(QWidget *parent = nullptr);
    void Hello1();


    public slots:

    void Hello2();
    void Read1();

    private slots:
    void on_pushButton_clicked();

    Ui::MainWindow *ui;
    QUdpSocket *socket;

    #endif // MAINWINDOW_H

    MainWindow.cpp look like this.............................................

    #include "MainWindow.h"
    #include "ui_MainWindow.h"
    #include <QDebug>
    #include <QTimer>
    #include <QLabel>

    QTimer *timer = new QTimer();
    static QUdpSocket *socket;

    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)

    socket = new QUdpSocket(this);
    socket->bind(QHostAddress::LocalHost, 1234);
    connect(socket, SIGNAL(Read1()), this, SLOT(Read1()));
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()),this,SLOT(Hello2()));
    timer -> start(1000);

    // connect(timer, SIGNAL(timeout()),this,SLOT(Hello1()));
    // timer -> start(1000);

    ui -> pushButton -> setCheckable(true);


    delete ui;

    void MainWindow::Hello2()
    qDebug() << "update..";

    void MainWindow::Hello1()

    QByteArray Data;
    Data.append("Hello from UDP land");

    // char Name[1000];
    // std::cout << "Your message : ";
    // std::cin >> Name;
    // qDebug() << "Hello " << Name << "\n";

    socket->writeDatagram(Data, QHostAddress::LocalHost, 1234);


    void MainWindow::Read1()
    QByteArray buffer;
    buffer.resize(socket->pendingDatagramSize()); //bekleyen data miktarı

    QHostAddress sender;
    quint16 senderPort;

    if ( socket->readDatagram(, buffer.size(),&sender,&senderPort) != -1)

    qDebug() << "Message from: " << sender.toString();
    qDebug() << "Message port: " << senderPort;
    qDebug() << "Message: " << buffer;

    } else {
    ;// handle error

    void MainWindow::on_pushButton_clicked()

    ui ->label->setText("1");


    and main.cpp look like .......................

    #include "MainWindow.h"
    #include "MyUDP.h"

    #include <QApplication>

    int main(int argc, char *argv[])
    QApplication a(argc, argv);

    MainWindow client;
    MainWindow w;;
    return a.exec();


  • Lifetime Qt Champion

    @Tibet said in QT Udp socket:

    QObject::connect: No such signal QUdpSocket::Read

    And that's correct - QUdpSocket has no such signal.

    /edit: and please fix your post to use the code tags to make the code more readable!

  • @Tibet

    QObject::connect: No such signal QUdpSocket::Read

    Not only as @Christian-Ehrlicher says, but in addition tell us clearly which line you get this error on, and what the code of the line is? Because I don't see any call at all to QUdpSocket::Read anywhere in the code you show, so I don't even see how you could get that error message; if I didn't know better, I'd say you either have not copied & pasted the error message, or your code is not as shown....

  • 14:15:32: Starting /home/tibet/build-qtDeneme12-Desktop-Debug/qtDeneme12 ...
    QObject::connect: No such signal QUdpSocket::Read1() in ../qtDeneme12/MainWindow.cpp:19
    QObject::connect: (receiver name: 'MainWindow')
    QObject::connect: No such signal QUdpSocket::Read1() in ../qtDeneme12/MainWindow.cpp:19
    QObject::connect: (receiver name: 'MainWindow')

  • Lifetime Qt Champion

    @Tibet Again: there is no such signal in QUdpSocket!

  • @Tibet
    So, as suspected, what you said was the error message never was the error message.... Please, if you post questions take the time to copy & paste the correct code and the correct error message, else people waste time trying to help you.

    And again additional to @Christian-Ehrlicher .

    I'm sorry, but if you have not already done so you really need to read Signals & Slots and have a proper understanding before you will get anywhere in Qt. Just trying things won't help you.

    Also I strongly advise that you change over to the New Signal Slot Syntax before you go further. It will hep you by generating compiler messages when you have done something wrong.

  • I'm very new at Qt. I guess the error might be about signal and slot. because ---- connect (socket, SIGNAL (Read1 ()), this, SLOT (Read1 ())); --- this part doesn't work. I don't know exactly about MyUDP.h

  • Lifetime Qt Champion

    @Tibet said in QT Udp socket:

    connect (socket, SIGNAL (Read1 ()), this, SLOT (Read1 ())); --- this part doesn't work

    And again: we know that it does not work because QUdpSocket has no such signal (said already two times before but you're ignoring it). The documentation has a working code snippet so why don't you follow them?

  • @Tibet

    connect (socket, SIGNAL (Read1 ()), this, SLOT (Read1 ()));

    Yes, it does not work. Because socket is a QUdpSocket, and as per that documentation page there is no such signal (or any method) as QUdpSocket::Read1. There is a signal QUdpSocket::readRead, and there is a method QUdpSocket::readDatagram() which you might want to call in a slot on that signal....

  • @JonB thank u. I get it now <3. I used readyRead() and it was fixed.

  • @Tibet said in QT Udp socket:

    it was fixed.

    so if your issue is solved now, please don't forget to mark your post as such!

Log in to reply