day 4

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    QMessageBox msg(QMessageBox::Warning,
                    "夏天要走了",
                    "冬天要来了",
                    QMessageBox::Yes| QMessageBox::No,
                    this);
    int ret =msg.exec();
    if(ret==QMessageBox::Yes)
    {
        qDebug()<<"夏天要走了";
    }else{
        qDebug()<<"冬天要来了";
    }


}

void Widget::on_pushButton_7_clicked()
{
    bool ok;
        QString username = QInputDialog::getText(this, "用户名", "请输入用户名:", QLineEdit::Normal, "", &ok);
        if (!ok || username.isEmpty())
            return;

        QString password;
        bool passwordOk = false;

        while (!passwordOk) {
            password = QInputDialog::getText(this, "密码", "请输入密码:", QLineEdit::Password, "", &ok);
            if (!ok) {
                return; // 用户取消输入
            }
            if (password == "yourPassword") {
                passwordOk = true;
            } else {
                QMessageBox::critical(this, "登录失败", "密码错误,请重新输入。");
            }
        }

        QMessageBox msg(QMessageBox::Information,
                        "登录成功",
                        "用户名和密码正确",
                        QMessageBox::Ok,
                        this);
}

void Widget::on_pushButton_6_clicked()
{
    QMessageBox msg(QMessageBox::Warning,
                    "是否取消登录",
                    "是取消登录",
                    QMessageBox::Yes| QMessageBox::No,
                    this);

    int ret =msg.exec();
    if(ret==QMessageBox::Yes)
    {
        qDebug()<<"是取消登录";
    }else{
        qDebug()<<"否认取消登录";
    }

}

void Widget::on_pushButton_8_clicked()
{
    if (ui->username->text() == "admin" && ui->passworld->text() == "123456") {
           QMessageBox::information(this, "Login", "登录成功");
       } else {
           QMessageBox::warning(this, "Login", "登录失败");
           ui->username->clear();
           ui->passworld->clear();
       }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值