I have the next doubt, I have an exit button created on the graphic interface, and I want to attach the closeEvent to him I have the next code but I couldnt make it work.

Qt Code:
  1. MainWindow::MainWindow(QWidget *parent) :
  2.  
  3. QMainWindow(parent),
  4. ui(new Ui::MainWindow)
  5. {
  6. ui->setupUi(this);
  7.  
  8.  
  9. }
  10. void MainWindow::on_exit_clicked()
  11. {
  12. closeEvent( );
  13. }
  14.  
  15. void MainWindow::closeEvent(QCloseEvent *event) {
  16. QMessageBox::StandardButton resBtn = QMessageBox::question( this, "Images",
  17. tr("Are you sure to exit?\n"),
  18. QMessageBox::Cancel | QMessageBox::No | QMessageBox::Yes,
  19. QMessageBox::Yes);
  20. if (resBtn != QMessageBox::Yes) {
  21. event->ignore();
  22. } else {
  23. event->accept();
  24. }
  25. }
To copy to clipboard, switch view to plain text mode