init code

This commit is contained in:
2025-07-24 04:08:36 +08:00
commit 0430307f4b
22 changed files with 1186 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
#include "CUiManager.h"
#include "QGobangRule.h"
#include "Ui/widget.h"
using namespace NS_QGobangClient;
CUiManager* CUiManager::m_pInstance = nullptr;
CUiManager *CUiManager::getInstance()
{
if(m_pInstance == nullptr)
{
m_pInstance = new CUiManager();
}
return m_pInstance;
}
Widget *CUiManager::getWidget()
{
if(m_pWidget == nullptr)
{
m_pWidget = new Widget();
}
return m_pWidget;
}
CUiManager::CUiManager()
{
//记得初始化成nullptr
m_pWidget = nullptr;
}
+38
View File
@@ -0,0 +1,38 @@
#ifndef CUIMANAGER_H
#define CUIMANAGER_H
/***************************************************************
* @file CUiManager.h
* @author Art_Sakura
* @date 2025-07-24
* @brief 项目由单例设计模式控制, 该类是控制全部Ui单例类
* 所有父类Ui都应创建声明在此处, 方便统一管理
***************************************************************/
namespace NS_QGobangClient
{
/* 应使用头文件声明 cpp引用方法
防止相互包含 */
class Widget;
class CUiManager
{
public:
static CUiManager *getInstance();
Widget *getWidget();
private:
CUiManager();
private:
static CUiManager *m_pInstance;
//示例
Widget *m_pWidget;
};
}
#endif // CUIMANAGER_H
Binary file not shown.
+27
View File
@@ -0,0 +1,27 @@
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
OBJECTS_DIR = $$PWD/../build/$$TARGET/obj
MOC_DIR = $$PWD/../build/$$TARGET/moc
RCC_DIR = $$PWD/../build/$$TARGET/rcc
UI_DIR = $$PWD/../build/$$TARGET/ui
CONFIG += c++17
CONFIG -= debug_and_release debug_and_release_target
SOURCES += \
CUiManager.cpp \
main.cpp \
Ui\widget.cpp
HEADERS += \
CUiManager.h \
Ui\widget.h
FORMS += \
Ui\widget.ui
#引用QGobangTool库文件
INCLUDEPATH += ../QGobangTool/include
LIBS += -L$$OUT_PWD/../QGobangTool/lib -lQGobangTool
+16
View File
@@ -0,0 +1,16 @@
#include "widget.h"
#include "ui_widget.h"
using namespace NS_QGobangClient;
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
+37
View File
@@ -0,0 +1,37 @@
#ifndef WIDGET_H
#define WIDGET_H
/***************************************************************
* @file Widget.h
* @author Art_Sakura
* @date 2025-07-24
* @brief 该Ui为示例类, 后续会删除
***************************************************************/
#include <QWidget>
//记得加命名空间 添加命名空间后 UI文件也得加
//你也可以将UI的命名空间声明到外面, 这样就可以不用加命名空间了, 当然不推荐
namespace NS_QGobangClient
{
QT_BEGIN_NAMESPACE
namespace Ui {
class Widget;
}
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
private:
Ui::Widget *ui;
};
}
#endif // WIDGET_H
+19
View File
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NS_QGobangClient::Widget</class>
<widget class="QWidget" name="NS_QGobangClient::Widget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>Widget</string>
</property>
</widget>
<resources/>
<connections/>
</ui>
+17
View File
@@ -0,0 +1,17 @@
#include <QApplication>
#include "Ui/widget.h"
#include "CUiManager.h"
using namespace NS_QGobangClient;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//单例设计模式下, 引用比较过长, 长远的来看, 利大于弊
Widget *w = CUiManager::getInstance()->getWidget();
w->show();
return a.exec();
}