使用手动连接,将登录框中的取消按钮使用第二中连接方式,右击转到槽,在该槽函数中,调用关闭函数
将登录按钮使用qt4版本的连接到自定义的槽函数中,在槽函数中判断ui界面上输入的账号是否为"admin",密码是否为"123456",如果账号密码匹配成功,则输出“登录成功”,并关闭该界面,如果匹配失败,则输出登录失败,并将密码框中的内容清空
widget.cpp
#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget),text1(new QTextEdit)
{ui->setupUi(this);ui->labelab->setPixmap(QPixmap(":/pictrue/logo.png"));ui->labelab->setScaledContents(true);ui->username->setPixmap(QPixmap(":/pictrue/qq.png"));ui->username->setScaledContents(true);ui->password->setPixmap(QPixmap(":/pictrue/passwd.jpg"));ui->password->setScaledContents(true);ui->passwordEdit->setEchoMode(QLineEdit::Password);connect(ui->loginBin,SIGNAL(clicked()),this,SLOT(my_slot()));connect(text1,SIGNAL(),this,SLOT(my_slot1()));
}Widget::~Widget()
{delete ui;
}
void Widget::my_slot()
{if(ui->usrnameEdit->text()=="admin"){if(ui->passwordEdit->text()=="123456"){text1->setText("登录成功");text1->resize(80,50);text1->show();this->close();return;}}text1->setText("登录失败");ui->passwordEdit->setText("");text1->resize(80,50);text1->show();}void Widget::on_canceBin_clicked()
{this->close();}
widget.h
#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QTextEdit>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACEclass Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();private slots:void on_canceBin_clicked();void my_slot();private:Ui::Widget *ui;QTextEdit *text1;
};
#endif // WIDGET_H
QQ2024614-20213