Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

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

    General and Desktop
    2
    3
    597
    Loading More Posts
    • 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
      Coop4Free last edited by

      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.Hilk 1 Reply Last reply Reply Quote 0
      • J.Hilk
        J.Hilk Moderators @Coop4Free last edited by

        @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

        Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

        C 1 Reply Last reply Reply Quote 2
        • C
          Coop4Free @J.Hilk last edited by

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

          newConnection

          It works, thank you very much!

          1 Reply Last reply Reply Quote 1
          • First post
            Last post