重载closeevent
void MainWindow::closeEvent (QCloseEvent *event)
{
QMessageBox::StandardButton resBtn = \
QMessageBox::question( this, "closing...", \
tr("Are you sure?\n"),\
QMessageBox::Cancel | QMessageBox::No | QMessageBox::Yes, \
QMessageBox::Yes);
if (resBtn != QMessageBox::Yes) {
event->ignore();
} else {
event->accept();
}
}