"No such signal TcpServer" error in QObject::connect
-
Hello guys,
I tried to script a tcp server and I've almost done it. But right now I'm getting an error in my console output which says:
QObject::connect: No such signal QTcpServer::receiveRequest() Server started!
And I don't know how to fix that. I hope you guys can help me with it. Thanks for all answers!
Here is my code://TcpServer.hpp #ifndef TCPSERVER_HPP #define TCPSERVER_HPP #include <QObject> #include <QTcpServer> #include <QTcpSocket> class TcpServer : public QObject { Q_OBJECT public: explicit TcpServer(QObject *parent = nullptr); signals: public slots: void receiveRequest(); void sendData(long long); private: QTcpServer *server; }; #endif // TCPSERVER_HPP
//TcpServer.cpp #include "TcpServer.hpp" #include "ServerUi.hpp" #include <QDebug> #include <string> #include <iostream> static QTcpSocket *socket; TcpServer::TcpServer(QObject *parent) : QObject(parent) { server = new QTcpServer(this); connect(server, SIGNAL(receiveRequest()), this, SLOT(receiveRequest())); if(!server->listen(QHostAddress::Any, 1234)) { qDebug() << "Server could not start!"; } else { qDebug() << "Server started!"; } } void TcpServer::receiveRequest() { std::string receivedRequest; socket = server->nextPendingConnection(); socket->waitForReadyRead(1000); receivedRequest = socket->readAll().toStdString(); if(receivedRequest == "get270value") { sendData270(); } } void TcpServer::sendData(long long label270) { const char* convertedLabel = reinterpret_cast<char * const>(label270); socket->write(convertedLabel); }
-
Hello guys,
I tried to script a tcp server and I've almost done it. But right now I'm getting an error in my console output which says:
QObject::connect: No such signal QTcpServer::receiveRequest() Server started!
And I don't know how to fix that. I hope you guys can help me with it. Thanks for all answers!
Here is my code://TcpServer.hpp #ifndef TCPSERVER_HPP #define TCPSERVER_HPP #include <QObject> #include <QTcpServer> #include <QTcpSocket> class TcpServer : public QObject { Q_OBJECT public: explicit TcpServer(QObject *parent = nullptr); signals: public slots: void receiveRequest(); void sendData(long long); private: QTcpServer *server; }; #endif // TCPSERVER_HPP
//TcpServer.cpp #include "TcpServer.hpp" #include "ServerUi.hpp" #include <QDebug> #include <string> #include <iostream> static QTcpSocket *socket; TcpServer::TcpServer(QObject *parent) : QObject(parent) { server = new QTcpServer(this); connect(server, SIGNAL(receiveRequest()), this, SLOT(receiveRequest())); if(!server->listen(QHostAddress::Any, 1234)) { qDebug() << "Server could not start!"; } else { qDebug() << "Server started!"; } } void TcpServer::receiveRequest() { std::string receivedRequest; socket = server->nextPendingConnection(); socket->waitForReadyRead(1000); receivedRequest = socket->readAll().toStdString(); if(receivedRequest == "get270value") { sendData270(); } } void TcpServer::sendData(long long label270) { const char* convertedLabel = reinterpret_cast<char * const>(label270); socket->write(convertedLabel); }
@Coop4Free
easy enough, connect your receiveRequest slot to an signal that actually exists in the QTcpServer - Classyou have the following options:
- acceptError(QAbstractSocket::SocketError socketError)
- void newConnection()
- void destroyed(QObject *obj = nullptr)
- void objectNameChanged(const QString &objectName)
-
@Coop4Free
easy enough, connect your receiveRequest slot to an signal that actually exists in the QTcpServer - Classyou have the following options:
- acceptError(QAbstractSocket::SocketError socketError)
- void newConnection()
- void destroyed(QObject *obj = nullptr)
- void objectNameChanged(const QString &objectName)
@J-Hilk said in "No such signal TcpServer" error in QObject::connect:
newConnection
It works, thank you very much!