/** 使用非靜態API,屬性設置API **/ QMessageBox msgBox; msgBox.setWindowTitle("Note");/** 設置標題 **/ 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);/** 設置默認按鈕 **/ msgBox.setIcon(QMessageBox::Warning);/** 設置圖標 **/ int ret = msgBox.exec();/** 返回點擊的按鈕對應的整型值 **/ switch(ret){ case QMessageBox::Save: qDebug()<<QString::fromLocal8Bit("點擊了保存按鈕"); break; case QMessageBox::Discard: qDebug()<<QString::fromLocal8Bit("點擊了不保存按鈕"); break; case QMessageBox::Cancel: qDebug()<<QString::fromLocal8Bit("點擊了取消按鈕"); break; default: qDebug()<<"error!"; } /** 結束 **/ QMessageBox::warning(this,"Warning Message!!!","Becaful with the gap!!");/** 使用靜態API建立一個QMessageBox **/