Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:How to create a message box in Qt

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Qt Quick should be used for all UI development on mobile devices. The approach described in this article (based on QWidget) is deprecated.

This (archived) code example shows how to create a QMessageBox, a standard dialog for informing the user or for asking the user a question. You can set the message title and use either a custom or predefined icon. You can also specify that the message box is modal.

Article Metadata
Tested with
Devices(s): Emulator
Platform(s): S60 3rd Edition, S60 5th Edition
S60 5th Edition
S60 3rd Edition (initial release)
Keywords: QMessageBox
Created: james1980 (27 Dec 2008)
Last edited: hamishwillee (11 Oct 2012)


Various functions

  • To set Window Title.


  • This provide the informative text that provides a fuller description for the message.
 msgBox.setInformativeText("Do You Want any Help This???");


  • Sets the modality of the message box to windowModality.This allow to set the window modality if its true then we can't focus any other window until the msgBox is being closed.
  • This property holds collection of standard buttons in the message box.
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Save); 


Clickable URL in messageBox

msgbox->about(0, "", "<a href=''>Nokia Developer</a>");



#include <QtGui/QApplication>
#include <QMessageBox>
int main(int argc, char *argv[])
QApplication app(argc, argv);
QMessageBox msgBox;
msgBox.setText("Hello Here");
return 1;

Screen Shot

To read More about QMessageBox: click here


Receving Input from user

QMessageBox allows user to set predefined buttons (standard buttons), and then receive input when these button is clicked. setStandardButtons() allows to set these buttons, you can add more than one button at a time.

        QMessageBox msgBox;
//Set text
//Set predefined icon, icon is show on left side of text.
//set inforative text
msgBox.setInformativeText("Just show infornation.");
//Add ok and cancel button.
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
//Set focus of ok button
//execute message box. method exec() return the button value of cliecke button
int ret = msgBox.exec();
//User get input from returned value (ret). you can handle it here.
switch (ret) {
case QMessageBox::Save:
// Save was clicked
case QMessageBox::Ok:
// ok was clicked
// should never be reached

Static methods of QMessageBox

QMessageBox has three static method, warning(), information() and critical(), which alow to create messagebox, but it does not allow to set custom icon, informative text and detailed text.

//Create warning message box
QMessageBox::warning(0,"Warning", "Warning message text");
//Create information message box
QMessageBox::information(0, "Information", "Information message text");
//Create critical message box
QMessageBox::critical(0, "Critical", "Critical message text");



Code Example

Code Example

This page was last modified on 11 October 2012, at 01:14.
567 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.