Qt初学者,想在Qt主线程中使用信号槽机制来触发子线程的函数,但是编译时显示 error: collect2: error: ld returned 1 exit status 错误,请问该怎么解决?
workthread.h类(子线程类):
#ifndef WORKTHREAD_H
#define WORKTHREAD_H
#include <QObject>
#include <QThread>
#include <QDebug>
class MyThread : public QThread
{
protected:
//线程退出的标识量
volatile bool m_stop;
//void setdata();
void run()
{
qDebug() << "run begin";
data = new char[2];
l = 2;
emit getdata(data,l);
//QThread::exec(); //开启该线程的事件循环,线程不会退出
qDebug() << "run end";
}
public:
int* p = new int[1000];
MyThread()
{
m_stop = false;
}
//线程退出的接口函数,用户使用
char *data;
int l;
signals:
void getdata(char*,int);
private slots:
void senddata(char*,int);
};
void MyThread::senddata(char* data1,int len)
{
qDebug()<<data1[0];
delete []data1;
}
#endif // WORKTHREAD_H
主函数文件:
#include "widget.h"
#include <QApplication>
#include <iostream>
#include <QDebug>
#include <QObject>
#include "workthread.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// Widget w;
// w.show();
MyThread thread1;
thread1.start();
QObject::connect(&thread1, SIGNAL(getdata(char*,int)), &thread1, SLOT(senddata(char*,int)));
return a.exec();
}
编译报错如下: