gpt4 book ai didi

c++ - QThread - 没有这样的插槽

转载 作者:太空狗 更新时间:2023-10-29 20:27:15 24 4
gpt4 key购买 nike

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

什么导致连接失败?

最佳答案

在类定义之后放置一个Q_OBJECT:

class ComSendCallToScreenThread : public QThread 
{
Q_OBJECT

Qt4 documentation :

All classes that contain signals or slots must mention Q_OBJECT at the top of their declaration. They must also derive (directly or indirectly) from QObject.

关于c++ - QThread - 没有这样的插槽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16851347/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com