我正在尝试QT中的多线程服务器。但是,我不断收到这个恼人的错误:
错误:不是信号或插槽声明(第21行)
这是我的代码:
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
答案 0 :(得分:7)
错误消息可以准确地告诉您问题所在。您将成员变量声明为插槽,但它们不是。我会改变你的课程如下:
class MyThread : public QThread
{
Q_OBJECT
[..]
private: // or public:
QTcpSocket *socket;
int socketDescriptor;
};