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();
    }
}
相关推荐
2401_884602276 小时前
程序人生-Hello’s P2P
c语言·c++
初中就开始混世的大魔王6 小时前
2 Fast DDS Library概述
c++·中间件·信息与通信
MediaTea6 小时前
Python:collections.Counter 常用函数及应用
开发语言·python
LawrenceLan6 小时前
37.Flutter 零基础入门(三十七):SnackBar 与提示信息 —— 页面反馈与用户交互必学
开发语言·前端·flutter·dart
李昊哲小课6 小时前
Python json模块完整教程
开发语言·python·json
易醒是好梦6 小时前
Python flask demo
开发语言·python·flask
娇娇yyyyyy6 小时前
C++基础(6):extern解决重定义问题
c++
Neteen7 小时前
【数据结构-思维导图】第二章:线性表
数据结构·c++·算法