作业:
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
,login_btn(new QPushButton("login",this))
{
ui->setupUi(this);
login_btn->resize(151,71);
login_btn->move(210,290);
ui->username_lineEdit->setPlaceholderText("plz enter username");
ui->password_lineEdit->setPlaceholderText("plz enter password");
ui->password_lineEdit->setEchoMode(QLineEdit::Password);
connect(login_btn,SIGNAL(clicked()),this,SLOT(login_slot()));
}
Widget::~Widget()
{
delete login_btn;
delete ui;
}
void Widget::login_slot()
{
if(ui->username_lineEdit->text() == "admin" && ui->password_lineEdit->text() == "123456")
{
emit login_signal();
close();
}
else
{
QMessageBox msg(QMessageBox::Critical,
"critical",
"Username or password error!",
QMessageBox::Yes | QMessageBox::No,
this
);
int ret = msg.exec();
if(ret==QMessageBox::Yes)
{
ui->password_lineEdit->clear();
}
else
{
close();
}
}
}
void Widget::on_cannel_pushButton_clicked()
{
QMessageBox msg(QMessageBox::Question,
"question",
"Are you sure to quit?",
QMessageBox::Yes | QMessageBox::No,
this
);
int ret = msg.exec();
if(ret==QMessageBox::Yes)
{
close();
}
else
{
msg.close();
}
}