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. QTcpServer no such slot warning
Forum Updated to NodeBB v4.3 + New Features

QTcpServer no such slot warning

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 307 Views 1 Watching
  • 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.
  • P Offline
    P Offline
    Poldi
    wrote on last edited by
    #1

    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

    jeremy_kJ 1 Reply Last reply
    0
    • P Poldi

      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

      jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #2

      @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.
      Thanks

      The case of the slots names as declared needs to match that as used in creating the connection.
      newTcpConnection != NewTcpConnection

      This type of error is easier to catch with the function pointer versions of QObject::connect().

      Asking a question about code? http://eel.is/iso-c++/testcase/

      1 Reply Last reply
      3
      • P Offline
        P Offline
        Poldi
        wrote on last edited by
        #3

        Dohhhh

        Thanks

        P 1 Reply Last reply
        0
        • P Poldi

          Dohhhh

          Thanks

          P Offline
          P Offline
          Poldi
          wrote on last edited by
          #4

          I changed the code to this and it works

          connect(server_,&QTcpServer::newConnection, this, &TcpServer::NewTcpConnection);
          

          Thanks,

          1 Reply Last reply
          1
          • P Poldi has marked this topic as solved on

          • Login

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