Sunday, July 18, 2010

QMessageBox with decision making

QMessageBox can also be used to show information to the user, and the user have to make a decision; such as the confirm to quit dialog.

- Create one more button on the form using Qt Designer. Right click on the button and select Go to Slot...


- Select clicked()


- Add the code

QString text = QObject::tr("Are you sure to quit?");
QMessageBox msgBox(QObject::tr("Quit"), text, QMessageBox::Warning, QMessageBox::Yes|QMessageBox::Default, QMessageBox::No|QMessageBox::Escape, QMessageBox::NoButton);
if (msgBox.exec() == QMessageBox::Yes)
{
close();
}


QMessageBox with decision making