int ret = QMessageBox::question(this, "退出程序", "您是否确认退出\r\n");
if(ret == QMessageBox::StandardButton::Yes){
}else{
}
eg:
information
QMessageBox::information(NULL, "Title", "Content",
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
这是比较常用的一种用法,效果如下:
information原型:
StandardButton QMessageBox::information(QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton) [static]
第一个参数是父控件指针
第二个参数是标题
第三个参数是内容
第四个参数是窗口里面要多少个按钮(默认为OK)
第五个参数指定按下Enter时使用的按钮。(默认为NoButton,此时QMessageBox会自动选择合适的默认值。)