登录界面头文件:
#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();
signals:
void my_jump();
private slots:
void on_pushButton_clicked();
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
登录界面源文件:
#include "widget.h"
#include "ui_widget.h"
static QString rightAccount = "admin";
static QString rightPasswd = "123456";
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()
{
QString account = ui->lineEdit->text();
QString passwd = ui->lineEdit_2->text();
if(account.compare(rightAccount) == 0 && passwd.compare(rightPasswd) == 0){
this->close();
emit my_jump();
}else{
ui->lineEdit->clear();
ui->lineEdit_2->clear();
}
}
第二界面头文件:
#ifndef SECOND_H
#define SECOND_H
#include <QWidget>
namespace Ui {
class second;
}
class second : public QWidget
{
Q_OBJECT
public:
explicit second(QWidget *parent = nullptr);
~second();
public slots:
void jump_solt();
private:
Ui::second *ui;
};
#endif // SECOND_H
第二界面源文件:
#include "second.h"
#include "ui_second.h"
second::second(QWidget *parent) :
QWidget(parent),
ui(new Ui::second)
{
ui->setupUi(this);
this->setWindowTitle("second");
this->setWindowFlag(Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_TranslucentBackground);
}
void second::jump_solt(){
this->show();
}
second::~second()
{
delete ui;
}
主函数文件:
#include "widget.h"
#include "second.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
second s;
QObject::connect(&w, &Widget::my_jump, &s, &second::jump_solt);
return a.exec();
}