main.c
#include "widget.h"
#include "newwidget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
Newwidget n;
QObject::connect(&w,&Widget::jump,&n,&Newwidget::showNew);
QObject::connect(&n,&Newwidget::jump,&w,&Widget::dis);
return a.exec();
}
widget.c
#include "widget.h"
#include "ui_widget.h"
#include <QMessageBox>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
this->setWindowFlag(Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_TranslucentBackground);
// QMessageBox msg;
// msg.setText("hello");
// msg.exec();
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_pushButton_clicked()
{
if(ui->lineEdit->text() == "1" && ui->lineEdit_2->text() == "1")
{
QMessageBox msg(QMessageBox::Information,"信息","登录成功",QMessageBox::Yes);
int ret = msg.exec();
if(ret == QMessageBox::Yes)
{
this->close();
emit this->jump();
}
}
else
{
QMessageBox msg(QMessageBox::Critical,"错误","账号密码错误,是否重新登录",QMessageBox::Yes| QMessageBox::No);
int ret = msg.exec();
if(ret == QMessageBox::Yes)
{
ui->lineEdit->clear();
ui->lineEdit_2->clear();
}
else if (ret == QMessageBox::No)
{
this->close();
}
}
}
void Widget::dis()
{
this->show();
}
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
QT_BEGIN_NAMESPACE
namespace Ui {
class Widget;
}
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
private slots:
void on_pushButton_clicked();
public slots:
void dis();
private:
Ui::Widget *ui;
signals:
void jump();
};
#endif // WIDGET_H
newwidget.cpp
#include "newwidget.h"
#include "ui_newwidget.h"
#include <QMessageBox>
Newwidget::Newwidget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Newwidget)
{
ui->setupUi(this);
}
Newwidget::~Newwidget()
{
delete ui;
}
void Newwidget::showNew()
{
this->show();
}
void Newwidget::on_pushButton_clicked()
{
QMessageBox msg(QMessageBox::Information,"信息","你是否确定要推出登录",QMessageBox::Yes|QMessageBox::No);
int ret = msg.exec();
if(ret == QMessageBox::Yes)
{
this->close();
}
else if (ret == QMessageBox::No)
{
this->close();
emit this->jump();
}
}
newwidget.h
#ifndef NEWWIDGET_H
#define NEWWIDGET_H
#include <QWidget>
namespace Ui {
class Newwidget;
}
class Newwidget : public QWidget
{
Q_OBJECT
public:
explicit Newwidget(QWidget *parent = nullptr);
~Newwidget();
signals:
void jump();
public slots:
void showNew();
private slots:
void on_pushButton_clicked();
private:
Ui::Newwidget *ui;
};
#endif // NEWWIDGET_H