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

                                                                             ^


  • 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;
    };@



  • 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

    Hi,

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.