赞
踩
思维导图
使用手动连接,将登录框中的取消按钮使用qt4版本的连接到自定义的槽函数中,在自定义的槽函数中调用关闭函数将登录按钮使用qt5版本的连接到自定义的槽函数中,在槽函数中判断ui界面上输入的账号是否为"admin",密码是否为"123456",如果账号密码匹配成功,则输出“登录成功”,并关闭该界面,如果匹配失败,则输出登录失败,并将密码框中的内容清空自己完成一个使用qss的登陆窗口界面。
头文件:
- #ifndef WIDGET_H
- #define WIDGET_H
-
- #include <QWidget>
- #include <QString>
- #include <QDebug>
-
- 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_btn2_clicked();
- void my_slot();
- void bt1_slot();
-
- private:
- Ui::Widget *ui;
- };
- #endif // WIDGET_H

源文件:
- #include "widget.h"
- #include "ui_widget.h"
-
- Widget::Widget(QWidget *parent)
- : QWidget(parent)
- , ui(new Ui::Widget)
- {
- ui->setupUi(this);
- //去掉头部
- this->setWindowFlag(Qt::FramelessWindowHint);
- //去掉空白的地方
- this->setAttribute(Qt::WA_TranslucentBackground);
- //连接按钮2的信号和槽函数 基于qt4版本
- connect(ui->btn2,SIGNAL(clicked()),this,SLOT(my_slot()));
- //连接信号和自定义槽函数,基于qt5版本的连接
- connect(ui->btn1,&QPushButton::clicked,this,&Widget::bt1_slot);
-
-
- }
-
- Widget::~Widget()
- {
- delete ui;
- }
-
-
-
-
- void Widget::on_btn2_clicked()
- {
-
- }
-
- void Widget::my_slot()
- {
- this->close();
-
- }
-
- void Widget::bt1_slot()
- {
- QString str1 = "admin";
- QString str2 = ui->usenameEdit->text();
- QString passwd = "123456";
- QString passwd2 = ui->passwdEdit->text();
- if(str1 == str2 && passwd == passwd2)
- {
- qDebug() << "登录成功!";
- this->close();
- }
- else
- {
- qDebug() << "登录失败";
-
- ui->passwdEdit->clear();
-
- }
-
-
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。