zoukankan      html  css  js  c++  java
  • 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();

    }

  • 相关阅读:
    Gym
    Gym
    Gym 101147B
    巴什博弈入门
    Hihocode 1304
    hihocoder 1441
    web前端
    ajax json html 结合
    关于获取各种浏览器可见窗口大小:
    原生JS 购物车及购物页面的cookie使用
  • 原文地址:https://www.cnblogs.com/vector-wei/p/5354221.html
Copyright © 2011-2022 走看看