1.
完善对话框,点击登录对话框,如果账号和密码匹配,则弹出信息对话框,给出提示”登录成功“,提供一个Ok按钮,用户点击Ok后,关闭登录界面,跳转到新的界面中
如果账号和密码不匹配,弹出错误对话框,给出信息”账号和密码不匹配,是否重新登录“,并提供两个按钮Yes|No,用户点击Yes后,清除密码框中的内容,继续让用户进行登录,如果用户点击No按钮,则直接关闭登录界面
如果用户点击取消按钮,则弹出一个问题对话框,给出信息”您是否确定要退出登录?“,并给出两个按钮Yes|No,用户点击Yes后,关闭登录界面,用户点击No后,关闭对话框,继续执行登录功能
要求:基于属性版和基于静态成员函数版至少各用一个
要求:尽量每行代码都有注释
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
// 窗口的相关设置
this->setWindowTitle("客户端登陆");
this->setWindowIcon(QIcon(":/pictrue/wodepeizhenshi.png"));
//标签的相关设置
ui->logoLab->setPixmap(QPixmap(":/pictrue/logo.png"));
ui->logoLab->setScaledContents(true);
//账号和密码
ui->userNameLab->resize(40,40);
ui->userNameLab->setPixmap(QPixmap(":/pictrue/userName.jpg"));
ui->userNameLab->setScaledContents(true);
ui->passwdLab->resize(40,40);
ui->passwdLab->setPixmap(QPixmap(":/pictrue/passwd.jpg"));
ui->passwdLab->setScaledContents(true);
ui->userNameEdit->setPlaceholderText("账号/手机号/邮箱");
ui->passwdEdit->setEchoMode(QLineEdit::Password);
//按钮设置
// connect(ui->cancelBtn, SIGNAL(clicked()), this, SLOT(close())); //按取消关闭窗口
connect(ui->loginBtn, &QPushButton::clicked, this, &Widget::my_slot);
//登录按钮
ui->loginBtn->setIcon(QIcon(":/pictrue/login.png"));
ui->cancelBtn->setIcon(QIcon(":/pictrue/cancel.png"));
}
Widget::~Widget()
{
delete ui;
}
void Widget::my_slot()
{
if("admin" == ui->userNameEdit->text())
{
if("123456" == ui->passwdEdit->text())
{
//用消息对话框这样的类 实例化一个对象
QMessageBox msg(
QMessageBox::Information, //图标
"提示框", //对话框标题
"登陆成功", //对话框文本
QMessageBox::Ok , //提供按钮
this); //父对象
//要用exec()函数执行对话框
int ret = msg.exec();
//对用户选中的按钮进行判断
if(ret == QMessageBox::Ok)
{
//按钮对应的槽函数处理
this->close();
emit jump();
}
}
else
{
//用消息对话框这样的类 实例化一个对象
QMessageBox msg(
QMessageBox::Critical, //图标
"提示框", //对话框标题
"密码错误", //对话框文本
QMessageBox::Yes | QMessageBox::No, //提供按钮
this); //父对象
//要用exec()函数执行对话框
int ret = msg.exec();
//对用户选中的按钮进行判断
if(ret == QMessageBox::Yes)
{
ui->passwdEdit->clear();
}
else
{
this->close();
}
}
}
}
void Widget::on_loginBtn_clicked()
{
}
void Widget::on_cancelBtn_clicked()
{
//直接调用静态成员函数
int ret = QMessageBox::question(this,
"问题",
"是否确定退出登录",
QMessageBox::Yes | QMessageBox::No);
//判断用户选的按钮
if(ret==QMessageBox::Yes)
{
//按钮对应的槽函数处理
this->close();
}
}
2.思维导图