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. How to write connect function to implement UDP Client
Forum Updated to NodeBB v4.3 + New Features

How to write connect function to implement UDP Client

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 261 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
    TokaraForest
    wrote on 15 Feb 2023, 12:47 last edited by
    #1

    Hello

    I am confused about writing connect function's parameters. I have read the documentation but i get "no matching member function for call to connect" error. My purpose is to trigger ReadyRead function when new data becomes ready on UDP. But I can't even compile the code at the beginning.

    widget.h :

    #ifndef WIDGET_H
    #define WIDGET_H
    
    #include <QWidget>
    
    QT_BEGIN_NAMESPACE
    namespace Ui { class Widget; }
    QT_END_NAMESPACE
    
    class QUdpSocket;
    
    class Widget : public QWidget
    {
        Q_OBJECT
    
    public:
        Widget(QWidget *parent = nullptr);
        ~Widget();
    
    private slots:
        void ReadyRead();
        void on_connectButton_clicked();
    
    private:
        Ui::Widget *ui;
        QUdpSocket *socketClient;
    };
    #endif // WIDGET_H
    

    widget.cpp :

    #include "widget.h"
    #include "ui_widget.h"
    #include <QUdpSocket>
    
    Widget::Widget(QWidget *parent)
        : QWidget(parent)
        , ui(new Ui::Widget)
    {
        ui->setupUi(this);
    
        socketClient = new QUdpSocket(this);
        connect(socketClient, &QUdpSocket::readyRead, this, Widget::ReadyRead());
    }
    
    Widget::~Widget()
    {
        delete ui;
    }
    
    void Widget::ReadyRead()
    {
        
    }
    
    void Widget::on_connectButton_clicked()
    {
        socketClient->bind(ui->spinBox->value(), QUdpSocket::ShareAddress);
    }
    

    In some posts, I saw that SIGNAL(ReadyRead()) is used as parameters. I thought that I should stick with the &QUdpSocket::readyRead parameter. I am not sure about 4. parameter in my example, that might be the mistake. Since I am new to Qt, I appriciate if you could help me. Thank you in advance.

    J 1 Reply Last reply 15 Feb 2023, 12:55
    0
    • T TokaraForest
      15 Feb 2023, 12:47

      Hello

      I am confused about writing connect function's parameters. I have read the documentation but i get "no matching member function for call to connect" error. My purpose is to trigger ReadyRead function when new data becomes ready on UDP. But I can't even compile the code at the beginning.

      widget.h :

      #ifndef WIDGET_H
      #define WIDGET_H
      
      #include <QWidget>
      
      QT_BEGIN_NAMESPACE
      namespace Ui { class Widget; }
      QT_END_NAMESPACE
      
      class QUdpSocket;
      
      class Widget : public QWidget
      {
          Q_OBJECT
      
      public:
          Widget(QWidget *parent = nullptr);
          ~Widget();
      
      private slots:
          void ReadyRead();
          void on_connectButton_clicked();
      
      private:
          Ui::Widget *ui;
          QUdpSocket *socketClient;
      };
      #endif // WIDGET_H
      

      widget.cpp :

      #include "widget.h"
      #include "ui_widget.h"
      #include <QUdpSocket>
      
      Widget::Widget(QWidget *parent)
          : QWidget(parent)
          , ui(new Ui::Widget)
      {
          ui->setupUi(this);
      
          socketClient = new QUdpSocket(this);
          connect(socketClient, &QUdpSocket::readyRead, this, Widget::ReadyRead());
      }
      
      Widget::~Widget()
      {
          delete ui;
      }
      
      void Widget::ReadyRead()
      {
          
      }
      
      void Widget::on_connectButton_clicked()
      {
          socketClient->bind(ui->spinBox->value(), QUdpSocket::ShareAddress);
      }
      

      In some posts, I saw that SIGNAL(ReadyRead()) is used as parameters. I thought that I should stick with the &QUdpSocket::readyRead parameter. I am not sure about 4. parameter in my example, that might be the mistake. Since I am new to Qt, I appriciate if you could help me. Thank you in advance.

      J Offline
      J Offline
      JonB
      wrote on 15 Feb 2023, 12:55 last edited by
      #2

      @TokaraForest said in How to write connect function to implement UDP Client:

      connect(socketClient, &QUdpSocket::readyRead, this, &Widget::ReadyRead);
      
      T 1 Reply Last reply 15 Feb 2023, 13:04
      2
      • J JonB
        15 Feb 2023, 12:55

        @TokaraForest said in How to write connect function to implement UDP Client:

        connect(socketClient, &QUdpSocket::readyRead, this, &Widget::ReadyRead);
        
        T Offline
        T Offline
        TokaraForest
        wrote on 15 Feb 2023, 13:04 last edited by
        #3

        @JonB Thank you!

        1 Reply Last reply
        0
        • T TokaraForest has marked this topic as solved on 15 Feb 2023, 13:04

        1/3

        15 Feb 2023, 12:47

        • Login

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