【无标题】

在子程序中调用主程序函数

主程序:
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()
{}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值