主函数
#include "work2.h"
#include "success.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Work2 w;
w.show();
Success s;
QObject::connect(&w, &Work2::WtoSsignal, &s, &Success::SuccessSlots);
return a.exec();
}
第一个界面
#include "work2.h"
#include "ui_work2.h"
Work2::Work2(QWidget *parent) :
QWidget(parent),
ui(new Ui::Work2)
{
ui->setupUi(this);
this->setFixedSize(this->width(), this->height());
this->setWindowFlag(Qt::FramelessWindowHint);
//上部logo
QMovie *mv = new QMovie(":/pictrue/qq2.gif");
ui->log_lab->setMovie(mv);
mv->start();
//输入框设置
ui->account_line->setStyleSheet("background-color:white; border-radius:5px;");
ui->pwd_line->setStyleSheet("background-color:white; border-radius:5px;");
//按钮设置
ui->login_btn->setStyleSheet("background-color:white; border-radius:10px;");
ui->cancel_btn->setStyleSheet("background-color:white; border-radius:10px;");
//基于qt4版本的connect
connect(ui->cancel_btn, SIGNAL(clicked()), this, SLOT(cancel_slots()));
//基于qt5版本的connect
connect(ui->login_btn, &QPushButton::clicked, this, &Work2::login_slots);
}
Work2::~Work2()
{
delete ui;
}
//登录的槽
void Work2::login_slots()
{
if(ui->account_line->text() == "admin" && ui->pwd_line->text() == "123456"){
QMessageBox *msg_success = new QMessageBox(QMessageBox::Information,
"登录成功",
"点击跳转",
QMessageBox::Ok,
this);
int res = msg_success->exec();
if(res == QMessageBox::Ok){
//发送信号
emit WtoSsignal();
this->close();
}
}else{
int res = QMessageBox::critical(this,
"登录失败",
"账号和密码不匹配,是否重新登录",
QMessageBox::Yes | QMessageBox::No);
if(res == QMessageBox::Yes){
ui->pwd_line->clear();
}else{
this->close();
}
}
}
//取消的槽
void Work2::cancel_slots()
{
int res = QMessageBox::question(this,
"退出",
"您是否确定要退出登录?",
QMessageBox::Yes | QMessageBox::No);
if(res == QMessageBox::Yes){
this->close();
}
}
第二个界面
#include "success.h"
#include "ui_success.h"
Success::Success(QWidget *parent) :
QWidget(parent),
ui(new Ui::Success)
{
ui->setupUi(this);
QMovie *mv = new QMovie(":/pictrue/car.gif");
ui->label->setMovie(mv);
mv->start();
this->setWindowFlag(Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_TranslucentBackground);
}
Success::~Success()
{
delete ui;
}
void Success::on_pushButton_clicked()
{
this->close();
}
void Success::SuccessSlots()
{
this->show();
}