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. QT Udp socket
QtWS25 Last Chance

QT Udp socket

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 852 Views
  • 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.
  • T Offline
    T Offline
    Tibet
    wrote on last edited by
    #1

    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>

    QT_BEGIN_NAMESPACE
    namespace Ui { class MainWindow; }
    QT_END_NAMESPACE

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    void Hello1();

    signals:

    public slots:

    void Hello2();
    void Read1();
    

    private slots:
    void on_pushButton_clicked();

    private:
    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>
    #include<iostream>

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

    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    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);
    

    }

    MainWindow::~MainWindow()
    {
    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.data(), 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;
    
    client.Hello1();
    
    MainWindow w;
    w.show();
    return a.exec();
    

    }

    JonBJ 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #2

      @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!

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • T Tibet

        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>

        QT_BEGIN_NAMESPACE
        namespace Ui { class MainWindow; }
        QT_END_NAMESPACE

        class MainWindow : public QMainWindow
        {
        Q_OBJECT

        public:
        MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
        void Hello1();

        signals:

        public slots:

        void Hello2();
        void Read1();
        

        private slots:
        void on_pushButton_clicked();

        private:
        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>
        #include<iostream>

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

        MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
        {
        ui->setupUi(this);

        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);
        

        }

        MainWindow::~MainWindow()
        {
        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.data(), 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;
        
        client.Hello1();
        
        MainWindow w;
        w.show();
        return a.exec();
        

        }

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @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....

        1 Reply Last reply
        0
        • T Offline
          T Offline
          Tibet
          wrote on last edited by
          #4

          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')

          Christian EhrlicherC JonBJ 2 Replies Last reply
          -1
          • T Tibet

            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')

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

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

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            0
            • T Tibet

              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')

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @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.

              1 Reply Last reply
              2
              • T Offline
                T Offline
                Tibet
                wrote on last edited by
                #7

                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

                JonBJ 1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @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?

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  2
                  • T Tibet

                    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

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #9

                    @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....

                    T 1 Reply Last reply
                    2
                    • JonBJ JonB

                      @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....

                      T Offline
                      T Offline
                      Tibet
                      wrote on last edited by
                      #10

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

                      Pablo J. RoginaP 1 Reply Last reply
                      0
                      • T Tibet

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

                        Pablo J. RoginaP Offline
                        Pablo J. RoginaP Offline
                        Pablo J. Rogina
                        wrote on last edited by
                        #11

                        @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!

                        Upvote the answer(s) that helped you solve the issue
                        Use "Topic Tools" button to mark your post as Solved
                        Add screenshots via postimage.org
                        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                        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