Archived:How to create interactive messagebox for getting user response in Qt
Article Metadata
Tested with
Devices(s): Emulator
Compatibility
Platform(s): S60 3rd Edition, S60 5th Edition
Article
Keywords: QMessageBox
Created: (28 Dec 2008)
Last edited: valderind4
(20 Sep 2009)
Contents |
Introduction
In this example a messagebox with three buttons is created. User can click on any of these buttons and depending on that a different function can be performed.
Preconditions
- Install latest Qt for S60 see Qt for S60 - Installation packages
- Check this link for installation guide: How to install the package.
- Go through this article: Getting started with Qt for S60
- Download Qt creator IDE V 4.5: http://www.qtsoftware.com/downloads
Various Function
- Holds the informative text that provides a fuller description for the message.
msgBox.setInformativeText("Do you want to save your changes?");
- Holds collection of standard buttons in the message box.
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
- Sets the buttons that gets activated when the Escape key is pressed to button.
msgBox.setEscapeButton(QMessageBox::Close);
- To set The window title
msgBox.setWindowTitle("HELLO WORLD");
Code
#include <QtGui/QApplication>
#include <QMessageBox>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMessageBox msgBox;
msgBox.setText("The document has been modified.");
msgBox.setInformativeText("Do you want to save your changes?");
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Save);
int ret = msgBox.exec();
app.quit();
return 1;
}
Screen Shot
More about QMessageBox
More about QMessageBox

