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

}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
  • 2021-06-14
  • 2022-12-23
  • 2021-06-18
猜你喜欢
  • 2021-10-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案