1、登录界面:输入用户名和密码,正确则登陆进入主界面,失败则提示。
2、界面
3、逻辑处理
-
#include "logindialog.h"
-
#include "ui_logindialog.h"
-
#include <QLineEdit>
-
#include <QMessageBox>
-
LoginDialog::LoginDialog(QWidget *parent) :
-
QDialog(parent),
-
ui(new Ui::LoginDialog)
-
{
-
ui->setupUi(this);
-
}
-
-
LoginDialog::~LoginDialog()
-
{
-
delete ui;
-
}
-
-
void LoginDialog::loginButtonClickSlots()
-
{
-
QLineEdit *usrName = ui->UserName;
-
QLineEdit*passWord = ui->PassWord;
-
-
if (usrName->text() == "xiaoming")
-
{
-
if(passWord->text() == "123456")
-
{
-
accept();
-
}
-
else
-
{
-
QMessageBox::warning(this,"waring","username or password error",QMessageBox::Yes);
-
}
-
}
-
else
-
{
-
QMessageBox::warning(this,"waring","username or password error",QMessageBox::Yes);
-
}
-
}
-
#include "widget.h"
-
#include <QApplication>
-
#include "logindialog.h"
-
int main(int argc, char *argv[])
-
{
-
QApplication a(argc, argv);
-
Widget w;
-
LoginDialog loginWin;
-
if (loginWin.exec() == QDialog::Accepted)
-
{
-
w.show();
-
return a.exec();
-
}
-
return 0;
-
}
附加需求:
(1)密码用黑点显示,选项控制是否用黑点显示密码
设置密码LineEdit的echoMode属性是什么
(2)密码错误清除用户名和密码
LineEdit->clear()
阅读(1502) | 评论(0) | 转发(0) |