Friday, July 9, 2010

Simple QMessageBox

In the last exercise "A simple PushButton to quit, built as a Qt Gui Application", the app was generate in Qt Designer without any coding. The signal from the button was connected to close() directly. In this exercise, we will have our slot to display a MessageBox before exit.

In Qt Designed, right click on the button and select Go to Slot...



Select clicked(), and click OK.



The method of MainWindow::on_pushButton_clicked() will be generated automatically.

Insert the code:

void MainWindow::on_pushButton_clicked()
{
QMessageBox msgBox;
msgBox.setText("It's going to Quit!");
msgBox.exec();
}




Save, Build and Run the application.