框架搭建
This commit is contained in:
parent
c2138c8440
commit
4f5da95276
17
.clang-format
Normal file
17
.clang-format
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# .clang-format
|
||||||
|
|
||||||
|
# 风格格式化
|
||||||
|
BasedOnStyle: Google
|
||||||
|
# 4 空格缩进
|
||||||
|
IndentWidth: 4
|
||||||
|
# 连续对齐变量的声明
|
||||||
|
AlignConsecutiveDeclarations: true
|
||||||
|
# 指针左侧对齐
|
||||||
|
PointerAlignment: Left
|
||||||
|
# 访问说明符(public、private等)的偏移
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
# 大括号
|
||||||
|
BreakBeforeBraces: Custom
|
||||||
|
BraceWrapping:
|
||||||
|
# 函数定义后面大括号在新行
|
||||||
|
AfterFunction: true
|
12
.clangd
Normal file
12
.clangd
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
Hover:
|
||||||
|
ShowAKA: Yes
|
||||||
|
Diagnostics:
|
||||||
|
UnusedIncludes: None # 禁用未使用头文件提示
|
||||||
|
Suppress: [
|
||||||
|
anon_type_definition, # 禁用匿名的typedef提示
|
||||||
|
unused-variable, # 禁用未使用变量提示
|
||||||
|
unused-function, # 禁用未使用函数提示
|
||||||
|
unused-includes, # 禁用未使用的头文件提示
|
||||||
|
]
|
||||||
|
ClangTidy:
|
||||||
|
Remove: misc-unused-alias-decls
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -30,3 +30,5 @@
|
|||||||
*.exe
|
*.exe
|
||||||
*.out
|
*.out
|
||||||
*.app
|
*.app
|
||||||
|
build
|
||||||
|
CMakeLists.txt.use*
|
||||||
|
38
CMakeLists.txt
Normal file
38
CMakeLists.txt
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
project(nettrans LANGUAGES CXX)
|
||||||
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
set(CMAKE_PREFIX_PATH
|
||||||
|
"C:/Dev/GNU/Boost"
|
||||||
|
"C:/Qt/Qt5.14.2/5.14.2/mingw73_64"
|
||||||
|
)
|
||||||
|
|
||||||
|
if (MSVC)
|
||||||
|
if (GBK)
|
||||||
|
add_compile_options(/source-charset:utf-8)
|
||||||
|
else()
|
||||||
|
add_compile_options(/utf-8)
|
||||||
|
endif()
|
||||||
|
# 以下抑制,主要作用与三方库。
|
||||||
|
add_compile_options(/wd4018) #有符号与无符号的比较
|
||||||
|
add_compile_options(/wd4800) #将值强制为布尔值“true”或“false”(性能警告)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_SYSTEM_NAME MATCHES "Windows")
|
||||||
|
MESSAGE(STATUS "Add MinGW Param.")
|
||||||
|
add_compile_options(-finput-charset=utf-8)
|
||||||
|
add_compile_options(-fexec-charset=utf-8)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
message(STATUS "System: ${CMAKE_SYSTEM_NAME}")
|
||||||
|
message(STATUS "Compiler C ID: ${CMAKE_CXX_COMPILER_ID}")
|
||||||
|
message(STATUS "Compiler CXX ID: ${CMAKE_CXX_COMPILER_ID}")
|
||||||
|
|
||||||
|
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
|
||||||
|
|
||||||
|
add_subdirectory(net_server)
|
||||||
|
add_subdirectory(net_com)
|
||||||
|
add_subdirectory(net_client)
|
74
net_client/.gitignore
vendored
Normal file
74
net_client/.gitignore
vendored
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
# This file is used to ignore files which are generated
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
*~
|
||||||
|
*.autosave
|
||||||
|
*.a
|
||||||
|
*.core
|
||||||
|
*.moc
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
*.orig
|
||||||
|
*.rej
|
||||||
|
*.so
|
||||||
|
*.so.*
|
||||||
|
*_pch.h.cpp
|
||||||
|
*_resource.rc
|
||||||
|
*.qm
|
||||||
|
.#*
|
||||||
|
*.*#
|
||||||
|
core
|
||||||
|
!core/
|
||||||
|
tags
|
||||||
|
.DS_Store
|
||||||
|
.directory
|
||||||
|
*.debug
|
||||||
|
Makefile*
|
||||||
|
*.prl
|
||||||
|
*.app
|
||||||
|
moc_*.cpp
|
||||||
|
ui_*.h
|
||||||
|
qrc_*.cpp
|
||||||
|
Thumbs.db
|
||||||
|
*.res
|
||||||
|
*.rc
|
||||||
|
/.qmake.cache
|
||||||
|
/.qmake.stash
|
||||||
|
|
||||||
|
# qtcreator generated files
|
||||||
|
*.pro.user*
|
||||||
|
CMakeLists.txt.user*
|
||||||
|
|
||||||
|
# xemacs temporary files
|
||||||
|
*.flc
|
||||||
|
|
||||||
|
# Vim temporary files
|
||||||
|
.*.swp
|
||||||
|
|
||||||
|
# Visual Studio generated files
|
||||||
|
*.ib_pdb_index
|
||||||
|
*.idb
|
||||||
|
*.ilk
|
||||||
|
*.pdb
|
||||||
|
*.sln
|
||||||
|
*.suo
|
||||||
|
*.vcproj
|
||||||
|
*vcproj.*.*.user
|
||||||
|
*.ncb
|
||||||
|
*.sdf
|
||||||
|
*.opensdf
|
||||||
|
*.vcxproj
|
||||||
|
*vcxproj.*
|
||||||
|
|
||||||
|
# MinGW generated files
|
||||||
|
*.Debug
|
||||||
|
*.Release
|
||||||
|
|
||||||
|
# Python byte code
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Binaries
|
||||||
|
# --------
|
||||||
|
*.dll
|
||||||
|
*.exe
|
||||||
|
|
45
net_client/CMakeLists.txt
Normal file
45
net_client/CMakeLists.txt
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
project(net_client LANGUAGES CXX)
|
||||||
|
|
||||||
|
set(CMAKE_AUTOUIC ON)
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
set(CMAKE_AUTORCC ON)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
|
||||||
|
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
|
||||||
|
|
||||||
|
set(PROJECT_SOURCES
|
||||||
|
main.cpp
|
||||||
|
mainwidget.cpp
|
||||||
|
mainwidget.h
|
||||||
|
mainwidget.ui
|
||||||
|
)
|
||||||
|
|
||||||
|
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||||
|
qt_add_executable(net_client
|
||||||
|
MANUAL_FINALIZATION
|
||||||
|
${PROJECT_SOURCES}
|
||||||
|
)
|
||||||
|
# Define target properties for Android with Qt 6 as:
|
||||||
|
# set_property(TARGET net_client APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
|
||||||
|
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
|
||||||
|
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
|
||||||
|
else()
|
||||||
|
if(ANDROID)
|
||||||
|
add_library(net_client SHARED
|
||||||
|
${PROJECT_SOURCES}
|
||||||
|
)
|
||||||
|
# Define properties for Android with Qt 5 after find_package() calls as:
|
||||||
|
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
|
||||||
|
else()
|
||||||
|
add_executable(net_client
|
||||||
|
${PROJECT_SOURCES}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_link_libraries(net_client PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
|
11
net_client/main.cpp
Normal file
11
net_client/main.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include "mainwidget.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QApplication a(argc, argv);
|
||||||
|
MainWidget w;
|
||||||
|
w.show();
|
||||||
|
return a.exec();
|
||||||
|
}
|
14
net_client/mainwidget.cpp
Normal file
14
net_client/mainwidget.cpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include "mainwidget.h"
|
||||||
|
#include "./ui_mainwidget.h"
|
||||||
|
|
||||||
|
MainWidget::MainWidget(QWidget *parent)
|
||||||
|
: QWidget(parent)
|
||||||
|
, ui(new Ui::MainWidget)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
MainWidget::~MainWidget()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
23
net_client/mainwidget.h
Normal file
23
net_client/mainwidget.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef MAINWIDGET_H
|
||||||
|
#define MAINWIDGET_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
namespace Ui {
|
||||||
|
class MainWidget;
|
||||||
|
}
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class MainWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
MainWidget(QWidget *parent = nullptr);
|
||||||
|
~MainWidget();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::MainWidget *ui;
|
||||||
|
};
|
||||||
|
#endif // MAINWIDGET_H
|
19
net_client/mainwidget.ui
Normal file
19
net_client/mainwidget.ui
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>MainWidget</class>
|
||||||
|
<widget class="QWidget" name="MainWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>800</width>
|
||||||
|
<height>600</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>MainWidget</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
6
net_com/CMakeLists.txt
Normal file
6
net_com/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
cmake_minimum_required (VERSION 3.8)
|
||||||
|
project (net_com)
|
||||||
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
|
||||||
|
|
||||||
|
add_library(net_com STATIC net_com.h net_com.cpp)
|
3
net_com/net_com.cpp
Normal file
3
net_com/net_com.cpp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#include "net_com.h"
|
||||||
|
|
||||||
|
CCommunicate::CCommunicate(){}
|
9
net_com/net_com.h
Normal file
9
net_com/net_com.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#ifndef NET_COM_HEADER
|
||||||
|
#define NET_COM_HEADER
|
||||||
|
|
||||||
|
class CCommunicate {
|
||||||
|
public:
|
||||||
|
CCommunicate();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
8
net_server/CMakeLists.txt
Normal file
8
net_server/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
cmake_minimum_required (VERSION 3.8)
|
||||||
|
project (net_server)
|
||||||
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
|
||||||
|
include_directories(../net_com)
|
||||||
|
|
||||||
|
add_executable(net_server main.cpp net_server.cpp net_server.h)
|
||||||
|
target_link_libraries(net_server PRIVATE net_com)
|
9
net_server/main.cpp
Normal file
9
net_server/main.cpp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include "net_server.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
CNetServer server;
|
||||||
|
server.run();
|
||||||
|
std::cout << "Done" << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
8
net_server/net_server.cpp
Normal file
8
net_server/net_server.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include "net_server.h"
|
||||||
|
|
||||||
|
CNetServer::CNetServer(){}
|
||||||
|
|
||||||
|
void CNetServer::run()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
17
net_server/net_server.h
Normal file
17
net_server/net_server.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef NET_SERVER_HEADER
|
||||||
|
#define NET_SERVER_HEADER
|
||||||
|
|
||||||
|
#include "net_com.h"
|
||||||
|
|
||||||
|
class CNetServer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CNetServer();
|
||||||
|
|
||||||
|
public:
|
||||||
|
void run();
|
||||||
|
private:
|
||||||
|
CCommunicate communi_{};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Reference in New Issue
Block a user