线程emit send(int)提示 error: undefined reference to `MyThread::send(int)'

若定义void MyThread::send(int)
{
}

编译时提示No such signal QThread::send(int)

QThread类头文件

#ifndef MYTHREAD_H
#define MYTHREAD_H

#include <QThread>

class MyThread : public QThread
{
signals:
    void send(int);

public:
    MyThread();

protected:
    void run();
};

#endif // MYTHREAD_H

QThread .cpp文件

#include "mythread.h"

MyThread::MyThread()
{

}

void MyThread::run()
{
    int i = 9;
    emit send(i);
}

void MyThread::send(int)
{

}

连接线程信号和主线程的槽函数

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    m_thread = new MyThread;
    connect(m_thread,SIGNAL(send(int)),this,SLOT(UpdateSlot()));

}

1.在MyThread类添加 Q_OBJECT ;
2.再删除void MyThread::send(int)
{
} (信号函数是不需要实现的)
3.重新编译或者删掉编译出来的文件夹重新运行,即可;亲测了可以

https://blog.csdn.net/jack_20/article/details/77650766