C++DAY47

头文件

cpp 复制代码
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
#include <QDebug>


QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
signals:
    void my_signal();
public slots:
    void my_slot();
    void my_on();

private:
    Ui::Widget *ui;
};
#endif // WIDGET_H

源文件

cpp 复制代码
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setWindowTitle("300英雄");
    this->setWindowIcon(QIcon(":/pic/d.gif"));
    this->setWindowFlag(Qt::FramelessWindowHint);

    ui->labe1->setPixmap(QPixmap(":/pic/5.jpg"));
    ui->labe1->setScaledContents(true);
    ui->labe2->setPixmap(QPixmap(":/pic/6.jpg"));
    ui->labe2->setScaledContents(true);
    ui->labe3->setPixmap(QPixmap(":/pic/3.gif"));
    ui->labe3->setScaledContents(true);

    ui->username->setPlaceholderText("账号");
    ui->password->setPlaceholderText("密码");
    ui->password->setEchoMode(QLineEdit::Password);

    this->connect(ui->Btn2,SIGNAL(clicked()),this,SLOT(my_slot()));

    connect(ui->Btn1,&QPushButton::clicked,this,&Widget::my_on);
}

Widget::~Widget()
{
    delete ui;
}



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

void Widget::my_on()
{
    if(ui->username->text() == "admin")
    {
        if(ui->password->text() == "123456")
        {
            qDebug() << "登录成功";
            this->close();
        }
        else
        {
            qDebug() << "登录失败";
            ui->password->clear();
        }
    }
    else
    {
        qDebug() << "登录失败";
        ui->username->clear();
        ui->password->clear();
    }
}
相关推荐
Despacito0o2 分钟前
C语言基础:变量与进制详解
java·c语言·开发语言
nightunderblackcat23 分钟前
进阶向:人物关系三元组,解锁人物关系网络的钥匙
开发语言·python·开源·php
光头闪亮亮1 小时前
C++凡人修仙法典 - 宗门版-上
c++
光头闪亮亮1 小时前
C++凡人修仙法典 - 宗门版-下
c++
John_ToDebug2 小时前
Chromium base 库中的 Observer 模式实现:ObserverList 与 ObserverListThreadSafe 深度解析
c++·chrome·性能优化
科大饭桶2 小时前
C++入门自学Day11-- String, Vector, List 复习
c语言·开发语言·数据结构·c++·容器
范范之交2 小时前
JavaScript基础语法two
开发语言·前端·javascript
Felven2 小时前
C. Game of Mathletes
c语言·开发语言
点云SLAM2 小时前
C++中内存池(Memory Pool)详解和完整示例
开发语言·c++·内存管理·内存池·new/delete·malloc/free
程高兴3 小时前
遗传算法求解冷链路径优化问题matlab代码
开发语言·人工智能·matlab