You Are Here:

Community: Wiki

This page was last modified on 5 November 2009, at 12:45.

How to create a message box in Qt for Symbian

From Forum Nokia Wiki

(Redirected from How to create a message box)
Reviewer Approved   


ID Creation date 27 December 2008
Platform S60 3rd Edition, S60 5th Edition Tested on devices Emulator
Category Qt for S60 Subcategory UI


Keywords (APIs, classes, methods, functions): QMessageBox

Introduction

The code given below shows means for informing the user or for asking the user a question and receiving an answer.

The QMessagebox class can be use for this purpose. It generate a message box that displays a primary text to alert the user to a situation.

The QMessageBox class provides a modal dialog for informing the user or for asking the user a question and receiving an answer. You can use QMessageBox to show information/warning message to user. QMessageBox has functionality to set title of message dialog. QMessageBox allows to show message with icon (allow both type of icon i.e. predefined and custom).


Download Links


Various Function

  • To set Window Title.
 msgBox.setWindowTitle("HELP");

Image:Hekp.JPG

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

Image:Hekp.JPG

  • 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.
msgBox.setWindowModality(Qt::ApplicationModal);
  • This property holds collection of standard buttons in the message box.
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Save); 

Image:Msgbox.JPG


Clickable URL in messageBox

msgbox->about(0, "Forum.nokia.com", "<a href='http://www.forum.nokia.com'>Forum Nokia</a>");

Image:Msg6.JPG

Code

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

Screen Shot

To read More about QMessageBox: click here

Image:Qtmsgbox.jpg

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
msgBox.setText("Testing..");
//Set predefined icon, icon is show on left side of text.
msgBox.setIcon(QMessageBox::Information);
//set inforative text
msgBox.setInformativeText("Just show infornation.");
//Add ok and cancel button.
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
//Set focus of ok button
msgBox.setDefaultButton(QMessageBox::Ok);
 
//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
break;
case QMessageBox::Ok:
// ok was clicked
break;
default:
// should never be reached
break;
}

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");

ScreenShots

Image:QtMessageBox.JPG

Code Example

Code Example


More about QMessageBox visit: http://pepper.troll.no/s60prereleases/doc/qmessagebox.html

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fE25E455E25A6E2582E25E454E25BE44E2595E25E455E259CE25A8E25E456E2594E25B6E25E454E25BBE25B6E25E457E25AE45E25B1E25E455E2588E259BE25E455E25BBE25BAE25E457E259FE25AE44E25E454E25BFE25A1X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZseriesE5f60Q qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZuserE5ftagQSxs60X qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ