head.h
#ifndef FIRST01WND_H
#define FIRST01WND_H
#include <QMainWindow>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QDebug>
QT_BEGIN_NAMESPACE
namespace Ui { class first01wnd; }
QT_END_NAMESPACE
class first01wnd : public QMainWindow
{
Q_OBJECT
signals:
private slots:
void loginbtn_clicked_slots();
void logoutbtn_clicked_slots();
public:
first01wnd(QWidget *parent = nullptr);
~first01wnd();
private:
Ui::first01wnd *ui;
QLabel *label1;
QLabel *label_account;
QLabel *label_password;
QLineEdit *edit_account;
QLineEdit *edit_password;
QPushButton *pushbtn_login;
QPushButton *pushbtn_logout;
};
#endif // FIRST01WND_H
fun.cpp
#include "first01wnd.h"
#include "ui_first01wnd.h"
first01wnd::first01wnd(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::first01wnd)
{
ui->setupUi(this);
this->setFixedSize(600,400);
this->setWindowIcon(QIcon("D:/qt/2Q1e/icon/QQ.png"));
this->setWindowTitle("QQ");
label1 = new QLabel(this);
label1->setPixmap(QPixmap("D:/qt/2Q1e/icon/logo.png"));
label1->resize(600,200);
label1->setScaledContents(true);
label_account = new QLabel(this);
label_account->resize(25,25);
label_account->move(100,250);
label_account->setScaledContents(true);
label_account->setPixmap(QPixmap("D:/qt/2Q1e/icon/zhanghao.png"));
label_password = new QLabel(this);
label_password->resize(25,25);
label_password->move(100,300);
label_password->setScaledContents(true);
label_password->setPixmap(QPixmap("D:/qt/2Q1e/icon/denglumima.png"));
edit_account = new QLineEdit(this);
edit_account->resize(150,25);
edit_account->setPlaceholderText("账号/手机号/邮箱");
edit_account->move(150,250);
edit_password = new QLineEdit(this);
edit_password->resize(150,25);
edit_password->setPlaceholderText("密码");
edit_password->setEchoMode(QLineEdit::Password);
edit_password->move(150,300);
pushbtn_login = new QPushButton(QString("登录"),this);
pushbtn_login->resize(50,30);
pushbtn_login->move(400,350);
pushbtn_logout = new QPushButton(QString("退出"),this);
pushbtn_logout->resize(50,30);
pushbtn_logout->move(480,350);
this->connect(pushbtn_login,SIGNAL(clicked()),this,SLOT(loginbtn_clicked_slots()));
this->connect(pushbtn_logout,SIGNAL(clicked()),this,SLOT(logoutbtn_clicked_slots()));
}
first01wnd::~first01wnd()
{
delete ui;
}
void first01wnd:: loginbtn_clicked_slots()
{
QString account_text = this->edit_account->text();
QString password_text = this->edit_password->text();
if((account_text == "admin" ) && (password_text == "123456") )
{
qDebug()<<"登录成功";
close();
}
else
{
qDebug()<<"用户名与密码不匹配";
this->edit_password->clear();
}
}
void first01wnd:: logoutbtn_clicked_slots()
{
close();
}
main.cpp
#include "first01wnd.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
first01wnd w;
w.show();
return a.exec();
}