QT开发之关闭程序时提示是否关闭程序(转)
头文件:
#include <QCloseEvent>
.h中申明:
void closeEvent(QCloseEvent *event);
.cpp中添加
//关闭
void Core::closeEvent(QCloseEvent *event)
{
if(QMessageBox::Yes == QMessageBox::question(this, tr("退出程序"),
QString(tr("确认退出程序?")),
QMessageBox::Yes | QMessageBox::No))
{
event->accept();
}
else
{
event->ignore();
}
}