QTcpServer no such slot warning
Solved
General and Desktop
-
I'm trying to figure out why the following code gives a warning that the slot NewTcpServer is not found
#include <QTcpServer> #include <QTcpSocket> class TcpServer : public QObject { Q_OBJECT public: static const char *kSettingsGroup; explicit TcpServer(QObject *parent = nullptr); ~TcpServer(); bool ServerUp(); public slots: void NewTcpConnection(); void StartServer(QHostAddress ipAddr, int port); void StopServer(); void CreateRemoteClient(); signals: private: QTcpServer *server_; QTcpSocket *socket_; };
#include "core/logging.h" TcpServer::TcpServer(QObject *parent) : QObject{parent} { server_ = new QTcpServer(this); connect(server_, SIGNAL(newConnection()),this,SLOT(newTcpConnection())); } TcpServer::~TcpServer() { } void TcpServer::StartServer(QHostAddress ipAddr, int port) { bool ok = false; qLog(Debug) << "Thread is " << thread(); ok = server_->listen(ipAddr, port); if (ok){ qLog(Debug) << "Server Started"; } } void TcpServer::NewTcpConnection() { //QTcpSocket *socket = server_->nextPendingConnection(); socket_ = server_->nextPendingConnection(); qLog(Debug) << "New Socket"; qLog(Debug) << socket_->currentReadChannel(); }
I've tried this code in a smal program and it works, but when I do this in a larger app, I get this warning.
Thanks -
@Poldi said in QTcpServer no such slot warning:
I'm trying to figure out why the following code gives a warning that the slot NewTcpServer is not found
public slots: void NewTcpConnection();
connect(server_, SIGNAL(newConnection()),this,SLOT(newTcpConnection()));
I've tried this code in a smal program and it works, but when I do this in a larger app, I get this warning.
ThanksThe case of the slots names as declared needs to match that as used in creating the connection.
newTcpConnection != NewTcpConnectionThis type of error is easier to catch with the function pointer versions of QObject::connect().
-