mainform.h
#ifndef MAINFORM_H
#define MAINFORM_H
#include <QWidget>
namespace Ui {
class MainForm;
}
class MainForm : public QWidget
{
Q_OBJECT
public:
explicit MainForm(QWidget *parent = nullptr);
~MainForm();
public slots:
void on_pushButton1_clicked();
public slots:
void on_show();
signals:
void on_jump();
private:
Ui::MainForm *ui;
};
#endif // FORM5_H
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();
public slots:
void on_pushButton2_clicked();
signals:
void on_jump();
public slots:
void on_show1();
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
main.cpp
#include "widget.h"
#include "mainform.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
MainForm s;
//连接两个槽函数
QObject::connect(&w,&Widget::on_jump,&s,&MainForm::on_show);
//跳回主界面
QObject::connect(&s,&MainForm::on_jump,&w,&Widget::on_show1);
return a.exec();
}
mainform.cpp文章来源:https://www.toymoban.com/news/detail-767010.html
#include "mainform.h"
#include "ui_mainform.h"
MainForm::MainForm(QWidget *parent) :
QWidget(parent),
ui(new Ui::MainForm)
{
ui->setupUi(this);
}
MainForm::~MainForm()
{
delete ui;
}
//展示第二个页面的函数
void MainForm::on_show(){
this->show();
}
//跳转回去
void MainForm::on_pushButton1_clicked()
{
emit on_jump();
this->hide();
}
widget.cpp文章来源地址https://www.toymoban.com/news/detail-767010.html
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
//跳转页面
void Widget::on_pushButton2_clicked()
{
this->show();
emit on_jump();
this->hide();
}
//展示页面
void Widget::on_show1()
{
this->show();
}
到了这里,关于QT实现两界面跳转的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!