void MainWindow::closeEvent(QCloseEvent *event) { if (maybeSave()) { writeSettings();//保留用户的配置 event->accept();//接受,关闭 } else { event->ignore();//忽略,不关闭 } }