SyunAmasi
SyunAmasi

Reputation: 71

Qt Error - error: Not a signal or slot declaration

I'm attempting to multi-thread server in QT. However, I keep getting this annoying error:

error: Not a signal or slot declaration (Line 21)

Here is my code:

mythread.h

#ifndef MYTHREAD_H
#define MYTHREAD_H

#include <QThread>
#include <QTcpSocket>

class MyThread : public QThread
{
    Q_OBJECT
public:
    explicit MyThread(int ID, QObject *parent = 0);
    void run();
signals:
    void error(QTcpSocket::SocketError socketerror);

public slots:
    void readyRead();
    void disconnected();

public slots:
    QTcpSocket *socket;
    int socketDescriptor; //Socket ID Number

};

#endif // MYTHREAD_H

Upvotes: 5

Views: 8117

Answers (1)

vahancho
vahancho

Reputation: 21250

The error message tells you exactly what the problem is. You declare member variables as being slots, but they are not. I would change your class as follows:

class MyThread : public QThread
{
    Q_OBJECT
    [..]

private: // or public:
    QTcpSocket *socket;
    int socketDescriptor;
};

Upvotes: 12

Related Questions