qt4 messagebox

refer to qt  QMessageBox Class Reference
头文件是:
 #include <QMessageBox>
1.
QMessageBox msgBox;
 msgBox.setText("The document has been modified.");
 msgBox.exec();
2.
 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();
 switch (ret) {
   case QMessageBox::Save:
       // Save was clicked
       break;
   case QMessageBox::Discard:
       // Don't Save was clicked
       break;
   case QMessageBox::Cancel:
       // Cancel was clicked
       break;
   default:
       // should never be reached
       break;
 }
3.
 int ret = QMessageBox::warning(this, tr("My Application"),tr("The document has been modified.\n" "Do you want to save your changes?"),
                                                         QMessageBox::Save | QMessageBox::Discard| QMessageBox::Cancel, QMessageBox::Save);
             

    QMessageBox::warning(this,"title","hello every body");
    QMessageBox::warning(this,"title",tr("hello every body"));

    QString name="song";
    int i=666;
    QMessageBox::warning(this,"title",tr("hello %1 ,%2").arg(name).arg(i));//参数只需指定%1 %2,不必%s %d
tr是QObject的一个静态成员函数,返回QString
QString QObject::tr ( const char * sourceText, const char * disambiguation = 0, int n = -1 )   [static]
Returns a translated version of sourceText, optionally based on a disambiguation string and value of n for strings containing plurals; otherwise returns sourceText itself if no appropriate translated string is available.





你可能感兴趣的:(String,application,Class,qt,reference)