Arm开发板+Qt学习之路-析构函数和对话框一起时

先记录一下代码

一:先将指针释放掉,在显示对话框

void MainWindow::canResponseError(SendCanMsgThread *sendCanMsgThread ){

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

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

}

此种情况下,先执行指针对应对象的析构函数,再执行对话框的显示

二:先显示对话框,再释放掉指针

 

void MainWindow::canResponseError(SendCanMsgThread *sendCanMsgThread ){

std::cerr<<" canResponseError "<<std::endl;
QMessageBox msgBox;

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

delete sendCanMsgThread;

sendCanMsgThread = NULL;

}

此种情况下,会先显示对话框,此时不执行指针对应对象的析构函数,直到点击关闭对话框后,析构函数才会执行

 

posted @ 2016-04-05 10:48  维克.贺仔  阅读(446)  评论(0编辑  收藏  举报