Unsolved Getting error related to QWebSocketServer
-
I am learning Network(tcpsocket, websocket...) and trying to write simple codes in Qt. I have watched [this video](link url)https://youtu.be/k4Y8wq_JwhM and tried to write the code provided in this video for myself, but I got error. I have a dialog window and added a new class named as WebServer. Then declared a private member named as mWebServer inside the dialog class. After that, inside the dialog constructor, I tried to use the listen method of the Webserver class (which inherits QWebSocketServer), but I got the error: "class WebServer has no member named listen".
I would appreciate if someone could help medialog.h:
#ifndef DIALOG_H #define DIALOG_H #include <QDialog> #include <QWebSocketServer> namespace Ui { class Dialog; } class WebServer; class Dialog : public QDialog { Q_OBJECT public: explicit Dialog(QWidget *parent = 0); ~Dialog(); private: Ui::Dialog *ui; WebServer *mWebServer; }; #endif // DIALOG_H
webserver.h:
#ifndef WEBSERVER_H #define WEBSERVER_H #include <QObject> #include <QWebSocketServer> class WebServer : public QWebSocketServer { Q_OBJECT public: explicit WebServer(QObject *parent = nullptr); signals: public slots: }; #endif // WEBSERVER_H
dialog.cpp:
#include "dialog.h" #include "ui_dialog.h" #include "webserver.h" Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { ui->setupUi(this); mWebServer = new WebServer(this); mWebServer->listen(QHostAddress::Any,1234); } Dialog::~Dialog() { delete ui; }
webserver.cpp:
#include "webserver.h" WebServer::WebServer(QObject *parent) : QWebSocketServer(parent) { }
main.cpp:
#include "dialog.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); Dialog w; w.show(); return a.exec(); } ```
-
@nanor Well, your WebServer class does not have listen method, so what do you expect?
"which inherits QWebSocketServer" - it does not, it inherits QObject, so please fix that. -
@jsulm Hi. Thank you for replying. I fixed that and updated my post, but I get the error: "no matching function for call to QWebSocketServer::QWebSocketServer(QObject*&) QWebSocketServer(parent)".
The picture of error:
-
@nanor
Go look at the definition of QWebSocketServer(const QString &serverName, QWebSocketServer::SslMode secureMode, QObject *parent = nullptr), and fix your definition/call to base constructor accordingly. -
Hi
It tells you it cant see any constructor that only takes a QObject *.
The reason for that is the constructor looks like
QWebSocketServer(const QString &serverName, QWebSocketServer::SslMode secureMode, QObject *parent = nullptr)So you must also include the servername and secureMode to the base class constructor
-
@JonB Thank you so much
-
@mrjj Hi. Thank you so much