Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 681
SyunAmasi Avatar asked Dec 20 '22 17:12

SyunAmasi


1 Answers

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;
};
like image 60
vahancho Avatar answered Dec 28 '22 10:12

vahancho