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.
MainWindow
::MainWindow(QWidget *parent
) :
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
void MainWindow::on_exit_clicked()
{
closeEvent( );
}
tr("Are you sure to exit?\n"),
event->ignore();
} else {
event->accept();
}
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
void MainWindow::on_exit_clicked()
{
closeEvent( );
}
void MainWindow::closeEvent(QCloseEvent *event) {
QMessageBox::StandardButton resBtn = QMessageBox::question( this, "Images",
tr("Are you sure to exit?\n"),
QMessageBox::Cancel | QMessageBox::No | QMessageBox::Yes,
QMessageBox::Yes);
if (resBtn != QMessageBox::Yes) {
event->ignore();
} else {
event->accept();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks