1、最简单的
QMessageBox msgBox;
msgBox.setText(“The document has been modified.”);
msgBox.exec(); //call exec() to show the message.
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;