jump.h
#ifndef JUMP_H
#define JUMP_H
#include <QWidget>
namespace Ui {
class Jump;
}
class Jump : public QWidget
{
Q_OBJECT
public:
explicit Jump(QWidget *parent = nullptr);
~Jump();
public slots:
void jumps();
private:
Ui::Jump *ui;
};
#endif // JUMP_H
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QMessageBox>
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_jump();
private slots:
void on_pushButton_clicked();
void on_cancel_clicked();
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
jump.cpp
#include "jump.h"
#include "ui_jump.h"
Jump::Jump(QWidget *parent) :
QWidget(parent),
ui(new Ui::Jump)
{
ui->setupUi(this);
}
void Jump::jumps()
{
this->show();
}
Jump::~Jump()
{
delete ui;
}
main.cpp
#include "widget.h"
#include "jump.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
Jump p;
QObject::connect(&w,&Widget::my_jump,&p,&Jump::jumps);
w.show();
return a.exec();
}
widget.h
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
this->setWindowFlag(Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_TranslucentBackground);
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_pushButton_clicked()
{
if(ui->username->text() == "admin" && ui->password->text() == "123456")
{
QMessageBox msg(QMessageBox::Information,
"提示",
"登录成功",
QMessageBox::Yes | QMessageBox::No,
this);
int rec = msg.exec();
if(rec == QMessageBox::Yes)
{
this->close();
emit my_jump();
}
}
else
{
int ret = QMessageBox::critical(this,"错误","账号或密码不匹配,请重新输入",
QMessageBox::Yes | QMessageBox::No);
if(ret == QMessageBox::Yes)
{
ui->username->clear();
ui->password->clear();
}
else if(ret == QMessageBox::No)
{
this->close();
}
}
}
void Widget::on_cancel_clicked()
{
int canret = QMessageBox::question(this,"问题","您确定要退出吗?",
QMessageBox::Yes | QMessageBox::No);
if(canret == QMessageBox::Yes)
{
this->close();
}
}