通过重写实现class CarWin :public CWinBase { public: CarWin(int x = 0, int y = 0, int w = 0, int h = 0); ~CarWin(); int doAction();//按钮分发:不同的按钮执行不同的业务 private: CLabel *title, *license_plate_lab, *total_lab, *remainder_lab; CEdit *license_plate_edit, *information_edit, *total_edit, *remainder_edit; CButt *query_btu, *storage_btu, *outbound_btu, *flushed_btu, *return_btu; };调用class CStorageWin :public CWinBase { public: CStorageWin(int x = 0, int y = 0, int w = 0, int h = 0); ~CStorageWin(); int doAction();//按钮分发:不同的按钮执行不同的业务 private: CLabel *title, *cpn_lab;//cpn=License plate number(车牌号) CEdit *cpn_edit; CButt *login_btu, *reg_btu; };里面的cpn_edit
时间: 2023-06-13 15:08:58 浏览: 188
可以通过以下方式来调用class CarWin中的cpn_edit:
1. 在CStorageWin中添加一个成员变量carWin,类型为CarWin*,并在构造函数中将它初始化为CarWin的实例。
2. 在CStorageWin的doAction方法中,通过carWin指针来访问CarWin的cpn_edit成员变量,例如carWin->cpn_edit。
示例代码如下:
class CStorageWin :public CWinBase {
public:
CStorageWin(int x = 0, int y = 0, int w = 0, int h = 0);
~CStorageWin();
int doAction();
private:
CLabel *title, *cpn_lab;
CEdit *cpn_edit;
CButt *login_btu, *reg_btu;
CarWin *carWin; // 添加一个CarWin指针
};
CStorageWin::CStorageWin(int x, int y, int w, int h) : CWinBase(x, y, w, h) {
title = new CLabel("车辆入库");
title->setPos(10, 10);
title->setSize(80, 20);
title->setParent(this);
cpn_lab = new CLabel("车牌号:");
cpn_lab->setPos(10, 40);
cpn_lab->setSize(80, 20);
cpn_lab->setParent(this);
cpn_edit = new CEdit();
cpn_edit->setPos(100, 40);
cpn_edit->setSize(120, 20);
cpn_edit->setParent(this);
login_btu = new CButt("入库");
login_btu->setPos(10, 80);
login_btu->setSize(60, 30);
login_btu->setParent(this);
reg_btu = new CButt("清空");
reg_btu->setPos(80, 80);
reg_btu->setSize(60, 30);
reg_btu->setParent(this);
carWin = new CarWin(); // 初始化CarWin指针
}
CStorageWin::~CStorageWin() {
delete title;
delete cpn_lab;
delete cpn_edit;
delete login_btu;
delete reg_btu;
delete carWin; // 释放CarWin指针
}
int CStorageWin::doAction() {
if (login_btu->isClick()) {
// 调用CarWin的doAction方法
carWin->doAction();
} else if (reg_btu->isClick()) {
cpn_edit->setText(""); // 清空车牌号输入框
}
return 0;
}
阅读全文