若定义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()));
}