QThread - 没有这样的插槽

时间:2013-05-31 06:49:43

标签: c++ qt

定义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

导致连接失败的原因是什么?

1 个答案:

答案 0 :(得分:6)

在课程定义后放置Q_OBJECT

class ComSendCallToScreenThread : public QThread 
{
   Q_OBJECT

Qt4 documentation

  

包含信号或广告位的所有类必须在。提及 Q_OBJECT   他们的声明顶部。他们也必须(直接或   间接地来自QObject。