QTday2作业

思维导图:

 使用手动连接,将登录框中的取消按钮使用qt4版本的连接到自定义的槽函数中,在自定义的槽函数中调用关闭函数;

将登录按钮使用qt5版本的连接到自定义的槽函数中,在槽函数中判断uü界面上输入的账号是否为"admin",密码是否为"123456",如果账号密码匹配成功,则输出"登录成功”,并关闭该界面,如果匹配失败,则输出登录失败,并将密码框中的内容清空

widget.h

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QDebug>

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = nullptr);
    ~Widget();

private:
    Ui::Widget *ui;

public slots:
    void cancel_close();
    void log_in();


};

#endif // WIDGET_H

main.cpp

#include "widget.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();

    return a.exec();
}

widget.cpp

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    //添加主图片
    ui->prolabel->setPixmap(QPixmap(":/pictrue/pictrue/R-C.gif"));
    ui->prolabel->setScaledContents(true);

    //添加账号图片
    ui->userlabel->setPixmap(QPixmap(":/pictrue/pictrue/3.png"));
    ui->userlabel->setScaledContents(true);
    //添加密码图片
    ui->passwdlabel->setPixmap(QPixmap(":/pictrue/pictrue/4.png"));
    ui->passwdlabel->setScaledContents(true);

    //设置用户输入框
    ui->userlineEdit->setPlaceholderText("账号");
    //设置密码输入框
    ui->passwdlineEdit->setPlaceholderText("密码");
    ui->passwdlineEdit->setEchoMode(QLineEdit::Password);

    //登陆按键
    ui->loginpushButton->setStyleSheet("background-color:rgb(55,229,93)");
    ui->cancelbut->setStyleSheet("background-color:rgb(55,229,93)");

    //取消键的设置
    connect(ui->cancelbut,SIGNAL(clicked()),this,SLOT(cancel_close()));

    //登陆键的设置
    connect(ui->loginpushButton,&QPushButton::clicked,this,&Widget::log_in);
}
Widget::~Widget()
{
    delete ui;
}

void Widget::cancel_close()
{
    this->close();
}

void Widget::log_in()
{
    //匹配显示登陆成功,并关闭界面
    if((ui->userlineEdit->text()=="admin") & (ui->passwdlineEdit->text()=="123456"))
    {
        //输出登陆成功
        qDebug() << "登陆成功";
        this->close();
    }
    else
    {
        //输出登录失败
        qDebug() << "登录失败";
        ui->passwdlineEdit->clear();
    }

    //不匹配清空,输出登录失败,并清空密码的内容
}

主界面:

登陆成功:

登录失败:

相关推荐

  1. <span style='color:red;'>QTday</span>4

    QTday4

    2024-01-13 13:18:01      58 阅读
  2. <span style='color:red;'>QTday</span>3

    QTday3

    2024-01-13 13:18:01      44 阅读
  3. <span style='color:red;'>QTDay</span>3

    QTDay3

    2024-01-13 13:18:01      30 阅读
  4. 作业2.2

    2024-01-13 13:18:01       45 阅读
  5. <span style='color:red;'>2</span>.<span style='color:red;'>2</span><span style='color:red;'>作业</span>

    2.2作业

    2024-01-13 13:18:01      53 阅读
  6. 2.2作业

    2024-01-13 13:18:01       46 阅读
  7. 假期作业 2.2

    2024-01-13 13:18:01       58 阅读
  8. 作业2024/2/2

    2024-01-13 13:18:01       52 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-13 13:18:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-13 13:18:01       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-13 13:18:01       82 阅读
  4. Python语言-面向对象

    2024-01-13 13:18:01       91 阅读

热门阅读

  1. 代码随想录算法训练营29期Day17|LeetCode 110,257,404

    2024-01-13 13:18:01       54 阅读
  2. 编程笔记 html5&css&js 034 HTML MathML

    2024-01-13 13:18:01       43 阅读
  3. 深入理解Golang中的接口与实例展示

    2024-01-13 13:18:01       57 阅读
  4. 在Centos7上配置NTP时间同步

    2024-01-13 13:18:01       53 阅读
  5. 想要安利给所有人的开发工具

    2024-01-13 13:18:01       53 阅读
  6. 什么是分治法算法思想?

    2024-01-13 13:18:01       54 阅读
  7. KY43 全排列

    2024-01-13 13:18:01       56 阅读
  8. GDAL的GDALWarpOptions结构体设置

    2024-01-13 13:18:01       52 阅读
  9. 类厂,变长参数,序列化

    2024-01-13 13:18:01       63 阅读