[英]Qt Error - error: Not a signal or slot declaration
I'm attempting to multi-thread server in QT. 我在QT尝试多线程服务器。 However, I keep getting this annoying error:
但是,我不断收到这个恼人的错误:
error: Not a signal or slot declaration (Line 21)
错误:不是信号或插槽声明(第21行)
Here is my code: 这是我的代码:
mythread.h 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;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.