在子程序中调用主程序函数
主程序:
ZHU_GUI.h
#include "StartWidget.h"
#include "ui_ZHU_GUI.h"
class ZHU_GUI: public QMainWindow
{
Q_OBJECT
public:
ZHU_GUI(QWidget *parent = nullptr);
~ZHU_GUI();
public:
void aaa();
SecendWidget* m_secendWidget;//声明次页面的指针
private:
Ui::ZHU_GUIClass ui;
}
ZHU_GUI.cpp
#include "ZHU_GUI.h"
#include "Global_define.h"
ZHU_GUI::ZHU_GUI(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
m_secendWidget = new SecendWidget;
//用m_startWidget调用另一个页面的功能
}
ZHU_GUI::~ZHU_GUI()
{}
void ZHU_GUI::aaa()
{
qDebug() << "aaaaaaaaaa";
}
次页面:SecendWidget.h
#include <QWidget>
#include "ui_SecendWidget.h"
class ZHU_GUI;
class SecendWidget: public QWidget
{
Q_OBJECT
public:
SecendWidget(QWidget *parent = nullptr);
~SecendWidget();
private:
Ui::SecendWidgetClass ui;
};
SecendWidget.cpp
#include "SecendWidget.h"
#include "Global_define.h"
#include "ZHU_GUI.h"//在头文件写此行会报错,存在两个程序相互引用的问题,在cpp引用主程序的头文件就没事
class ZHU_GUI* pGUI;
SecendWidget::SecendWidget(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
pGUI = (ZHU_GUI*)parent;
//然后就可以用pGUI调用主程序的函数了
pGUI->aaa();
}
SystemModeWidget::~SystemModeWidget()
{}