pommmm 2021-09-07 01:06 采纳率: 50%
浏览 35

Qt 子线程使用信号槽编译时提示: error: collect2: error: ld returned 1 exit status问题

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

编译报错如下:

img

  • 写回答

1条回答 默认 最新

  • qfl_sdu 2021-09-07 07:53
    关注

    自己给自己发信号?
    connect第一个参数是信号发送者指针,第二个参数是信号,第三个是接受者指针,第四个是槽函数

    评论

报告相同问题?

问题事件

  • 创建了问题 9月7日

悬赏问题

  • ¥15 视频编码 十六进制问题
  • ¥15 Xsheii7我安装这个文件的时候跳出来另一个文件已锁定文件的无一部分进程无法访问。这个该怎么解决
  • ¥15 unity terrain打包后地形错位,跟建筑不在同一个位置,怎么办
  • ¥15 FileNotFoundError 解决方案
  • ¥15 uniapp实现如下图的图表功能
  • ¥15 u-subsection如何修改相邻两个节点样式
  • ¥30 vs2010开发 WFP(windows filtering platform)
  • ¥15 服务端控制goose报文控制块的发布问题
  • ¥15 学习指导与未来导向啊
  • ¥15 求多普勒频移瞬时表达式