.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QDebug>
#include <QString>
#include <QMessageBox>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
signals:
void jump(); //跳转页面的自定义函数
public slots:
void login_solt(); //登录页面的自定义的槽函数
public:
Widget(QWidget *parent = nullptr);
~Widget();
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);
s = new client;
//更改窗口标题
this->setWindowTitle("光与夜之恋");
//logo图
ui->logo->setPixmap(QPixmap(":/qt/a1.webp"));
ui->logo->setScaledContents(true);
//用户名密码图
ui->userNamelab->setPixmap(QPixmap(":/qt/q1.webp"));
ui->userNamelab->setScaledContents(true);
ui->pwdlab->setPixmap(QPixmap(":/qt/2.webp"));
ui->pwdlab->setScaledContents(true);
//设置账户密码
ui->pwdEdit->setPlaceholderText("密码");
ui->pwdEdit->setEchoMode(QLineEdit::Password);
//将登录按钮连接到自定义的槽函数中
connect(ui->loginBtn,&QPushButton::clicked,this,&Widget::login_solt);
//将取消按钮连接到自定义的槽函数中
connect(ui->cancleBtn,SIGNAL(clicked()),this,SLOT(close()));
connect(this, &Widget::jump, s, &client::jump_slot);
}
Widget::~Widget()
{
delete ui;
}
void Widget::login_solt()
{
QString username=ui->userNameEdit->text();
QString pwd=ui->pwdEdit->text();
}
void Widget::on_loginBtn_clicked()
{
QString username=ui->userNameEdit->text();
QString pwd=ui->pwdEdit->text();
if(username=="admin"&&pwd=="123456")
{
qDebug()<<"登录成功";
int ret =QMessageBox::information(this,"提示","登录成功",QMessageBox::Ok);
if(ret==QMessageBox::Ok)
{
emit jump();
this->close();
}
}else
{
//qDebug()<<"账号密码不匹配,请重新登录!";
int ret =QMessageBox::critical(this,"提示","登录成功",QMessageBox::Yes|QMessageBox::No);
if(ret==QMessageBox::Yes)
{
//清除密码框内容
ui->pwdEdit->clear();
}
else
{
this->close();
}
}
}
void Widget::on_cancleBtn_clicked()
{
}
main
#include "widget.h"
#include <QApplication>
#include "client.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
client s;
QObject::connect(&w,&Widget::login_solt,&s,&client::jump_slot);
return a.exec();
}
.h
#ifndef CLIENT_H
#define CLIENT_H
#include <QDockWidget>
#include <QDebug>
#include <QString>
#include <QMessageBox>
namespace Ui {
class client;
}
class client : public QDockWidget
{
Q_OBJECT
public slots:
void jump_slot();
public:
explicit client(QWidget *parent = nullptr);
~client();
private:
Ui::client *ui;
};
#endif // CLIENT_H
#include "client.h"
#include "ui_client.h"
client::client(QWidget *parent) :
QDockWidget(parent),
ui(new Ui::client)
{
ui->setupUi(this);
//更改窗口标题
this->setWindowTitle("光与夜之恋");
//logo图
ui->logo->setPixmap(QPixmap(":/qt/592587c702e7f7674a6c7fa72fe21169.jpg"));
ui->logo->setScaledContents(true);
}
client::~client()
{
delete ui;
}
void client::jump_slot()
{
this->show();
}