使用手动连接,将登录框中的取消按钮使用第二中连接方式,右击转到槽,在该槽函数中,调用关闭函数
将登录按钮使用qt4版本的连接到自定义的槽函数中,在槽函数中判断ui界面上输入的账号是否为"admin",密码是否为"123456",如果账号密码匹配成功,则输出“登录成功”,并关闭该界面,如果匹配失败,则输出登录失败,并将密码框中的内容清空
widget.h
- #ifndef WIDGET_H
- #define WIDGET_H
-
- #include
- #include
-
- QT_BEGIN_NAMESPACE
- namespace Ui { class Widget; }
- QT_END_NAMESPACE
-
- class Widget : public QWidget
- {
- Q_OBJECT
-
- public:
- Widget(QWidget *parent = nullptr);
- ~Widget();
- private slots:
- void on_canceBin_clicked();
- void my_slot();
-
- void on_pos2_clicked();
-
- private:
- Ui::Widget *ui;
- QTextEdit *text1;
- };
- #endif // WIDGET_H
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->bel1->setPixmap(QPixmap(":/pictrue/logo.png"));//标签贴图的路劲
- ui->bel1->setScaledContents(true);//自动适应调节
- ui->bel2->setPixmap(QPixmap(":/pictrue/wodepeizhenshi.png"));//标签贴图的路劲
- ui->bel2->setScaledContents(true);//自动适应调节
- ui->bel3->setPixmap(QPixmap(":/pictrue/passwd.jpg"));//标签贴图的路劲
- ui->bel3->setScaledContents(true);//自动适应调节
- ui->idt2->setEchoMode(QLineEdit::Password);//设置密码
- connect(ui->pos1,SIGNAL(clicked()),this,SLOT(my_slot()));
- // connect(text1,SIGNAL(),this,SLOT(my_slot()));
- }
-
- Widget::~Widget()
- {
- delete ui;
- }
- void Widget::my_slot()
- {
- if(ui->idt1->text()=="123456")
- {
- if(ui->idt2->text()=="123456")
- {
- text1->setText("登录成功");
- text1->resize(80,50);
- text1->show();
- this->close();
- return;
- }
- }
- text1->setText("登录失败");
- ui->idt2->setText("");
- text1->resize(80,50);
- text1->show();
- }
- void Widget::on_canceBin_clicked()
- {
- this->close();
- }
-
-
- void Widget::on_pos2_clicked()
- {
- this->close();
- }
功能实现




思维导图
