我正在尝试实现一个自定义类,QTcpSocket
但似乎我的插槽在运行时无法识别,我总是得到:
Object::connect: No such slot QTcpSocket::timeoutSlot()
这是我的代码:
我的标题:
#ifndef CUSTOM_SOCKET_H
#define CUSTOM_SOCKET_H
#include <QTcpSocket>
#include <QTimer>
class CustomSocket : public QTcpSocket {
Q_OBJECT
public:
CustomSocket(QObject* = 0);
private:
QTimer *mAuthTimeout;
public slots:
void timeoutSlot();
};
#endif
执行:
#include "customSocket.h"
CustomSocket::CustomSocket(QObject *aParent):QTcpSocket(aParent)
{
mAuthTimeout = new QTimer();
connect(mAuthTimeout, SIGNAL(timeout()), this, SLOT(timeoutSlot()));
mAuthTimeout->start(5000);
}
void CustomSocket::timeoutSlot(){
std::cout << "Timeout " << std::endl;
}