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. "No such signal TcpServer" error in QObject::connect
QtWS25 Last Chance

"No such signal TcpServer" error in QObject::connect

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.2k Views
  • 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.
  • C Offline
    C Offline
    Coop4Free
    wrote on last edited by
    #1

    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);
    }
    
    J.HilkJ 1 Reply Last reply
    0
    • C Coop4Free

      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);
      }
      
      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @Coop4Free
      easy enough, connect your receiveRequest slot to an signal that actually exists in the QTcpServer - Class

      you have the following options:

      • acceptError(QAbstractSocket::SocketError socketError)
      • void newConnection()
      • void destroyed(QObject *obj = nullptr)
      • void objectNameChanged(const QString &objectName)

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      C 1 Reply Last reply
      2
      • J.HilkJ J.Hilk

        @Coop4Free
        easy enough, connect your receiveRequest slot to an signal that actually exists in the QTcpServer - Class

        you have the following options:

        • acceptError(QAbstractSocket::SocketError socketError)
        • void newConnection()
        • void destroyed(QObject *obj = nullptr)
        • void objectNameChanged(const QString &objectName)
        C Offline
        C Offline
        Coop4Free
        wrote on last edited by
        #3

        @J-Hilk said in "No such signal TcpServer" error in QObject::connect:

        newConnection

        It works, thank you very much!

        1 Reply Last reply
        1

        • Login

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