Please nominate your Qt Champions for 2021!

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

  • 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());


    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*)'

    What am I doing wrong here?

    Thanks and Regards,


  • 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

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

    void run();

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

    QTcpSocket* tcpSocket;
    int socketDescriptor;
    QString text;

  • 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?

  • Lifetime Qt Champion


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

Log in to reply