• Arm开发板+Qt学习之路-qt线程执行完毕发送signal主动释放线程内存


    header:

    #ifndef SENDCANMSGTHREAD_H
    #define SENDCANMSGTHREAD_H

    #include <QThread>
    #include "can/canUtils.h"
    #include <QTime>
    #include <iostream>


    class SendCanMsgThread : public QThread{

    Q_OBJECT
    public:
    SendCanMsgThread();
    ~SendCanMsgThread();

    signals:
    void canResponseError(SendCanMsgThread *sendCanMsgThread);

    };

    #endif // SENDCANMSGTHREAD_H

    cpp

    #include "can/sendCanMsgThread.h"

    SendCanMsgThread::SendCanMsgThread(){
    isRunning = true;
    responsed = false;
    currentRequestTimes = 0;
    }

    SendCanMsgThread::~SendCanMsgThread(){
    std::cerr<<" ~SendCanMsgThread() "<<std::endl;
    }

    void SendCanMsgThread::run(){
    if(1){
    emit canResponseError(this);
    }

    }

    mainWindow.cpp

    void MainWindow::showPickupStautus(){


    SendCanMsgThread *sendCanMsgThread = new SendCanMsgThread();

    sendCanMsgThread->start();

    connect(sendCanMsgThread,SIGNAL(canResponseError(SendCanMsgThread*)),this,SLOT(canResponseError(SendCanMsgThread *)));
    }

    //红色地方很重要,一个是指针传参的方式  二是信号和槽这只能定义参数类型,不能出现具体参数,否则提示No such signal

    void MainWindow::canResponseError(SendCanMsgThread *sendCanMsgThread ){
    //can通讯异常提示

    std::cerr<<" canResponseError "<<std::endl;
    delete sendCanMsgThread;
    sendCanMsgThread = NULL;

    QMessageBox msgBox;
    msgBox.setText("Could not get can response " );
    msgBox.exec();

    }

  • 相关阅读:
    HUE配置HBase
    HUE配置HIVE
    HUE配置hadoop
    HUE的安装
    CM (Cloudera Manager) 的安装,便于CDH的离线部署
    MapReduce -- 最短路径
    Mapreduce -- PageRank
    CentOS 建立本地yum源服务器
    js移动设备手机跳转地址代码
    离线存储
  • 原文地址:https://www.cnblogs.com/vector-wei/p/5354221.html
Copyright © 2020-2023  润新知