3

定义ComSendCallToScreenThread继承自QThread

class ComSendCallToScreenThread : public QThread 
{
    private slots:
        void readAnswer();
        void pauseSendingRequests();
};

void ComSendCallToScreenThread::run()
{
    connect(m_senderCom, SIGNAL(readyRead()), this, SLOT(readAnswer()));
    connect(m_senderCom, SIGNAL(readyRead()), this, SLOT(pauseSendingRequests()));
}

运行时报错:

Object::connect: No such slot QThread::readAnswer() in ComSendCallToScreenThread.cpp:47
Object::connect: No such slot QThread::pauseSendingRequests() in ComSendCallToScreenThread.cpp:48

是什么导致连接失败?

4

1 回答 1

6

Q_OBJECT在类定义之后放一个正确的:

class ComSendCallToScreenThread : public QThread 
{
   Q_OBJECT

Qt4文档

所有包含信号或槽的类都必须在其声明的顶部提及Q_OBJECT 。它们还必须(直接或间接)从 QObject 派生。

于 2013-05-31T06:56:05.750 回答