How to write connect function to implement UDP Client
-
wrote on 15 Feb 2023, 12:47 last edited by
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.
-
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.
wrote on 15 Feb 2023, 12:55 last edited by@TokaraForest said in How to write connect function to implement UDP Client:
connect(socketClient, &QUdpSocket::readyRead, this, &Widget::ReadyRead);
-
@TokaraForest said in How to write connect function to implement UDP Client:
connect(socketClient, &QUdpSocket::readyRead, this, &Widget::ReadyRead);
wrote on 15 Feb 2023, 13:04 last edited by@JonB Thank you!
-
1/3