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
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;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With