头文件
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();
}
}