Qt Forum

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

    [solved] linking error when setting up signals and slots within a thread

    General and Desktop
    2
    4
    790
    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.
    • K
      kpks last edited by

      Hello,

      I have a tcpServer class calling a thread when there is an incoming connection; The thread in-turn creates a tcpSocket and waits for data. I want the data to be analyzed/plotted. I tried setting up a signal on readyread connection to a slot defined in the thread.
      @void listenWriteThread::run()
      {
      QTcpSocket tcpSocket;
      if (!tcpSocket.setSocketDescriptor(socketDescriptor)) {
      emit error(tcpSocket.error());
      return;
      }

      connect(tcpSocket,SIGNAL(readyRead()),this,SLOT(analyzeThis()));@
      

      I get a No-matching function error:
      D:\kpks\software\tcpComm\listenWriteThread.cpp:18: error: no matching function for call to 'listenWriteThread::connect(QTcpSocket&, const char*, listenWriteThread* const, const char*)'
      connect(tcpSocket,SIGNAL(tcpSocket.readyRead()),this,SLOT(analyzeThis()));

      What am I doing wrong here?

      Thanks and Regards,
      kpks

                                                                               ^
      
      1 Reply Last reply Reply Quote 0
      • K
        kpks last edited by

        Sorry! That was atrocious doubt! I just forgot to make tcpSocket a pointer :(

        I changed my thread definition to have socket as a pointer:

        @class listenWriteThread : public QThread
        {
        Q_OBJECT

        public:
        listenWriteThread(int socketDescriptor, const QString &fortune, QObject *parent);

        void run();
        

        public slots:
        void analyzeThis();
        signals:
        void error(QTcpSocket::SocketError socketError);

        private:
        QTcpSocket* tcpSocket;
        int socketDescriptor;
        QString text;
        };@

        1 Reply Last reply Reply Quote 0
        • K
          kpks last edited by

          I have a new problem though, the connection is fine and my C client is sending data every 100ms but qt does nothing! My qt application is tcpComm.exe

          Then I get a windows error saying
          "the tcpCOmm.exe has encountered a problem and needs to close "

          Should I make this a separate thread?

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Hi,

            Did you initialize tcpSocket properly ? Did you update your run function ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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