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

}

转载于:https://www.cnblogs.com/vector-wei/p/5354221.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值