一、逻辑思路
1、创建三个QT界面类:oneform twoform threeform
2、之后继续创建三个c++类oneclass、twoclass、threeclass
3、在三个类中添加相应界面类的头文件至oneclass.cpp、twoclass.cpp、threeclass.cpp当中,创建静态公共类的指针和函数,并在oneclass.cpp中实现Init()方法并在函数中实例化静态类。此处之前需要对静态指针进行NULL赋值,其中最终要的是静态类的调用和实例化都需要加作用域指明
4、在main函数中加入三个cpp类头文件,并调用静态类的Init()方法(为实例化三个界面类的实例化),同时对oneform界面进行显示
程序结构
二、ComOneForm类
cpp文件
#include "comoneform.h"
oneform *ComOneForm::myoneform = NULL;
ComOneForm::ComOneForm()
{
}
void ComOneForm::InitForm()
{
myoneform = new oneform();
}
h文件
#ifndef COMONEFORM_H
#define COMONEFORM_H
#include "oneform.h"
class ComOneForm
{
public:
ComOneForm();
static oneform *myoneform;
static void InitForm();
};
#endif // COMONEFORM_H
二、oneform类
cpp文件
#include "oneform.h"
#include "ui_oneform.h"
#include "comtwoform.h"
#include "comthreeform.h"
oneform::oneform(QWidget *parent) :
QWidget(parent),
ui(new Ui::oneform)
{
ui->setupUi(this);
}
oneform::~oneform()
{
delete ui;
}
void oneform::on_ptn_go1_clicked()
{
this->hide();
ComTwoForm::mytwoform->show();
}
void oneform::on_ptn_go2_clicked()
{
this->hide();
ComThreeForm::mythreeform->show();
}
h文件
#ifndef ONEFORM_H
#define ONEFORM_H
#include <QWidget>
namespace Ui {
class oneform;
}
class oneform : public QWidget
{
Q_OBJECT
public:
explicit oneform(QWidget *parent = 0);
~oneform();
private slots:
void on_ptn_go1_clicked();
void on_ptn_go2_clicked();
private:
Ui::oneform *ui;
};
#endif // ONEFORM_H
四、main函数
#include "comoneform.h"
#include "comtwoform.h"
#include "comthreeform.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ComOneForm::InitForm();
ComTwoForm::InitForm();
ComThreeForm::InitForm();
ComOneForm::myoneform->show();
return a.exec();
}