#ifndef WIDGET_H #define WIDGET_H #include <QWidget> namespace Ui { class Widget; } class Widget : public QWidget { Q_OBJECT public: explicit Widget(QWidget *parent = nullptr); ~Widget(); private slots: void on_pushButton_clicked(); private: Ui::Widget *ui; }; #endif // WIDGET_H
#include "widget.h" #include "ui_widget.h" #include <QDebug> #include <QMessageBox> Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); } Widget::~Widget() { delete ui; } void Widget::on_pushButton_clicked() { QMessageBox messageBox; messageBox.setIcon(QMessageBox::Question); messageBox.setText("你确定要关闭窗体吗"); messageBox.setWindowTitle("提示"); QPushButton *yesbutton=messageBox.addButton("是",messageBox.YesRole); QPushButton *nobutton=messageBox.addButton("是",messageBox.NoRole); int res=messageBox.exec(); if(messageBox.clickedButton()==yesbutton) { qDebug()<<"点击yes"<<endl; } else { qDebug()<<"点击no"<<endl; } }
标签:Widget,QT,32,messageBox,QWidget,ui,QMessageBox,include From: https://www.cnblogs.com/zxtang/p/18181041