first commit

This commit is contained in:
www-git-cn 2024-03-03 23:55:56 +08:00
commit 24179fa464
20 changed files with 2316 additions and 0 deletions

42
app.pro Normal file
View File

@ -0,0 +1,42 @@
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets mqtt
CONFIG += c++11
ICON = icon.icns
TARGET = IoTCar
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
datamanager.cpp \
login.cpp \
main.cpp \
protocol.cpp \
signup.cpp \
tcpclient.cpp \
widget.cpp
HEADERS += \
datamanager.h \
login.h \
protocol.h \
signup.h \
tcpclient.h \
widget.h
FORMS += \
login.ui \
signup.ui \
widget.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
RESOURCES += \
imgs/icon.qrc

488
app.pro.user Normal file
View File

@ -0,0 +1,488 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 12.0.2, 2024-03-03T23:52:44. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
<value type="QByteArray">{d3fed20c-1c94-44fc-8f6a-4dbf39b54775}</value>
</data>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
<value type="qlonglong">1</value>
</data>
<data>
<variable>ProjectExplorer.Project.EditorSettings</variable>
<valuemap type="QVariantMap">
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
<value type="QString" key="language">Cpp</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
</valuemap>
</valuemap>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
<value type="QString" key="language">QmlJS</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
</valuemap>
</valuemap>
<value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
<value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
<value type="int" key="EditorConfiguration.IndentSize">4</value>
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
<value type="int" key="EditorConfiguration.PreferAfterWhitespaceComments">0</value>
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
<value type="int" key="EditorConfiguration.TabSize">8</value>
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap">
<valuemap type="QVariantMap" key="AutoTest.ActiveFrameworks">
<value type="bool" key="AutoTest.Framework.Boost">true</value>
<value type="bool" key="AutoTest.Framework.CTest">false</value>
<value type="bool" key="AutoTest.Framework.Catch">true</value>
<value type="bool" key="AutoTest.Framework.GTest">true</value>
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
<value type="bool" key="AutoTest.Framework.QtTest">true</value>
</valuemap>
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
<value type="int" key="AutoTest.RunAfterBuild">0</value>
<value type="bool" key="AutoTest.UseGlobal">true</value>
<valuemap type="QVariantMap" key="ClangTools">
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
<value type="int" key="ClangTools.ParallelJobs">4</value>
<value type="bool" key="ClangTools.PreferConfigFile">true</value>
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
</valuemap>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap">
<value type="QString" key="DeviceType">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 6.5.3 MinGW 64-bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 6.5.3 MinGW 64-bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt6.653.win64_mingw_kit</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="int" key="EnableQmlDebugging">0</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:\Users\25761\Desktop\build-app-Desktop_Qt_6_5_3_MinGW_64_bit-Debug</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">C:/Users/25761/Desktop/build-app-Desktop_Qt_6_5_3_MinGW_64_bit-Debug</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:\Users\25761\Desktop\build-app-Desktop_Qt_6_5_3_MinGW_64_bit-Release</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">C:/Users/25761/Desktop/build-app-Desktop_Qt_6_5_3_MinGW_64_bit-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Release</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
<value type="int" key="QtQuickCompiler">0</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2">
<value type="int" key="EnableQmlDebugging">0</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:\Users\25761\Desktop\build-app-Desktop_Qt_6_5_3_MinGW_64_bit-Profile</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">C:/Users/25761/Desktop/build-app-Desktop_Qt_6_5_3_MinGW_64_bit-Profile</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Profile</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
<value type="int" key="QtQuickCompiler">0</value>
<value type="int" key="SeparateDebugInfo">0</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">3</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">部署</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">部署</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:C:/Users/25761/Desktop/app/app.pro</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">C:/Users/25761/Desktop/app/app.pro</value>
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">C:/Users/25761/Desktop/build-app-Desktop_Qt_6_5_3_MinGW_64_bit-Debug</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.Target.1</variable>
<valuemap type="QVariantMap">
<value type="QString" key="DeviceType">Android.Device.Type</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">安卓 Qt 6.5.3 Clang arm64-v8a</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">安卓 Qt 6.5.3 Clang arm64-v8a</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{7c520419-6b2e-4709-ae24-2a8e3b2ab41b}</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="int" key="EnableQmlDebugging">0</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:\Users\25761\Desktop\build-app-Qt_6_5_3_Clang_arm64_v8a-Debug</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">C:/Users/25761/Desktop/build-app-Qt_6_5_3_Clang_arm64_v8a-Debug</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.2">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">复制应用程序的数据</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.AndroidPackageInstallationStep</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.3">
<value type="QString" key="BuildTargetSdk">android-33</value>
<value type="QString" key="BuildToolsVersion"></value>
<value type="QString" key="KeystoreLocation"></value>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建安卓 APK</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QmakeProjectManager.AndroidBuildApkStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">4</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:\Users\25761\Desktop\build-app-Qt_6_5_3_Clang_arm64_v8a-Release</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">C:/Users/25761/Desktop/build-app-Qt_6_5_3_Clang_arm64_v8a-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.2">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">复制应用程序的数据</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.AndroidPackageInstallationStep</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.3">
<value type="QString" key="BuildTargetSdk">android-33</value>
<value type="QString" key="BuildToolsVersion"></value>
<value type="QString" key="KeystoreLocation"></value>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建安卓 APK</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QmakeProjectManager.AndroidBuildApkStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">4</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Release</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2">
<value type="int" key="EnableQmlDebugging">0</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:\Users\25761\Desktop\build-app-Qt_6_5_3_Clang_arm64_v8a-Profile</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">C:/Users/25761/Desktop/build-app-Qt_6_5_3_Clang_arm64_v8a-Profile</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.2">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">复制应用程序的数据</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.AndroidPackageInstallationStep</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.3">
<value type="QString" key="BuildTargetSdk">android-33</value>
<value type="QString" key="BuildToolsVersion"></value>
<value type="QString" key="KeystoreLocation"></value>
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建安卓 APK</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QmakeProjectManager.AndroidBuildApkStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">4</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Profile</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
<value type="int" key="SeparateDebugInfo">0</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">3</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.AndroidDeployQtStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">部署</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">部署</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.AndroidDeployConfiguration2</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings">
<valuelist type="QVariantList" key="AndroidDeviceAbis">
<value type="QString">arm64-v8a</value>
<value type="QString">armeabi-v7a</value>
<value type="QString">armeabi</value>
</valuelist>
<value type="QString" key="AndroidDeviceSerialNumber">d03ac6da</value>
<value type="int" key="AndroidVersion.ApiLevel">33</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="Android.PostStartShellCmdListKey">
<value type="QString"></value>
</valuelist>
<valuelist type="QVariantList" key="Android.PreStartShellCmdListKey">
<value type="QString"></value>
</valuelist>
<valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="int" key="PE.EnvironmentAspect.Base">0</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">app</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.AndroidRunConfiguration:C:/Users/25761/Desktop/app/app.pro</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">C:/Users/25761/Desktop/app/app.pro</value>
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.TargetCount</variable>
<value type="qlonglong">2</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
<value type="int">22</value>
</data>
<data>
<variable>Version</variable>
<value type="int">22</value>
</data>
</qtcreator>

220
datamanager.cpp Normal file
View File

@ -0,0 +1,220 @@
#include "datamanager.h"
// DataManager* DataManager::p_this;
DataManager::DataManager(QObject *parent)
: QObject{parent}
{
qDebug() << "进入DataManager的构造函数";
tcpclient = TCPClient::getInstance();
connect(tcpclient, &TCPClient::TCPClientConnected, this, &DataManager::TCPClientConnected);
connect(tcpclient, &TCPClient::TCPClientDisconnected, this, &DataManager::TCPClientDisconnected);
connect(tcpclient, &TCPClient::recv_data, this, &DataManager::recv_from_server);
tcpclient->setServer("ourdocs.cn",35137);
tcpclient->setTimeOut(500);
tcpclient->configAndrun();
// tcpclient->setCallBack(recv_from_server);
protocol = Protocol::getInstance();
// p_this = this;
}
DataManager *DataManager::getInstance()
{
static DataManager datamanager_instance;
return &datamanager_instance;
}
void DataManager::TCPClientConnected()
{
connect_flag = true;
qDebug() << "emit connect_to_server successfully";
emit connect_to_server();
}
void DataManager::TCPClientDisconnected()
{
connect_flag = false;
qDebug() << "emit disconnect_from_server successfully";
// emit p_this->disconnect_from_server();
emit disconnect_from_server();
}
void DataManager::Register(QString username, QString password)
{
QByteArray data, data_encrypt;
data = protocol->data_maker(Protocol::REQUEST, QString("register"), QList<QString>{"user", username, "password", password});
data_encrypt = protocol->data_encrypt(data);
tcpclient->sendToserver(data_encrypt);
qDebug() << "发送注册信息" << data;
}
void DataManager::signin_request(QString username, QString password)
{
QByteArray data, data_encrypt;
data = protocol->data_maker(Protocol::REQUEST, QString("signin"), QList<QString>{"user", username, "password", password});
data_encrypt = protocol->data_encrypt(data);
tcpclient->sendToserver(data_encrypt);
qDebug() << "发送登录信息" << data;
}
void DataManager::account_cancellation(QString username)
{
QByteArray data, data_encrypt;
data = protocol->data_maker(Protocol::REQUEST, QString("cancellation"), QList<QString>{"name",username});
data_encrypt = protocol->data_encrypt(data);
tcpclient->sendToserver(data_encrypt);
qDebug() << "发送注销信息" << data;
}
void DataManager::update_namelist(QString username)
{
QByteArray data, data_encrypt;
data = protocol->data_maker(Protocol::REQUEST, QString("update_namelist"),QList<QString>{"name",username});
data_encrypt = protocol->data_encrypt(data);
tcpclient->sendToserver(data_encrypt);
qDebug() << "发送更新在线用户列表信息" << data;
}
void DataManager::parking()
{
QByteArray data, data_encrypt;
data = protocol->data_maker(Protocol::CODE, QString("park"), QString("parking_request"));
data_encrypt = protocol->data_encrypt(data);
tcpclient->sendToserver(data_encrypt);
qDebug() << "发送存车信息" << data;
}
void DataManager::pick_up(QString code)
{
QByteArray data, data_encrypt;
data = protocol->data_maker(Protocol::CODE, QString("pick"), code);
data_encrypt = protocol->data_encrypt(data);
tcpclient->sendToserver(data_encrypt);
qDebug() << "发送取车信息" << data;
}
void DataManager::recv_from_server(QByteArray data)
{
QByteArray data_decrypt;
data_decrypt = protocol->data_decrypt(data);
QList<QByteArray> list = data_decrypt.split('\n');
for (int i = 0; i < list.count(); i++)
{
QJsonDocument json_data = QJsonDocument::fromJson(list[i]);
if (json_data["type"] == "message")
{
emit new_message();
QString data, sendname;
sendname = json_data["action"].toString();
data = json_data["data"].toString();
emit update_text(sendname, data);
//接收到行车路线类型的消息
}
if(json_data["type"] == "code")
{
QString data, sendname;
sendname = json_data["action"].toString();
if(sendname == "pick")
{
data = json_data["data"].toString();
//取车时向服务端发送,不会接受该类信息
}
else if (sendname == "park")
{
data = json_data["data"].toString();
emit update_code(data);
//停车时服务端反馈的随机码
}
}
else if (json_data["type"] == "online_users")
{
int count;
QList<QString> online_users;
count = json_data["count"].toInt();
online_users = json_data["users"].toVariant().toStringList();
emit update_users(count, online_users);
qDebug() << "收到更新在线用户列表的信息" << online_users;
}
else if (json_data["type"] == "response")
{
if (json_data["action"] == "register")
{
bool register_flag;
QJsonObject json = json_data["content"].toObject();
QString result = json["result"].toString();
if(result == "true")
{
register_flag = true;
}
else
{
register_flag = false;
}
emit signup_response(register_flag);
qDebug() << "收到服务器响应的注册信息" << register_flag;
}
else if (json_data["action"] == "signin")
{
bool signin_flag;
QJsonObject json = json_data["content"].toObject();
QString result = json["result"].toString();
if(result == "true")
{
signin_flag = true;
}
else
{
signin_flag = false;
}
emit signin_response(signin_flag);
qDebug() << "收到服务器响应的登录信息" << signin_flag;
}
}
else
{
qDebug() << "收到未知类型的数据" << list[i];
return;
}
}
}
/*
void DataManager::send_text(QString sendname, QString text)
{
QByteArray data, data_encrypt;
data = protocol->data_maker(Protocol::MESSAGE, sendname, text);
data_encrypt = protocol->data_encrypt(data);
tcpclient->sendToserver(data_encrypt);
qDebug() << "群发文本信息" << data;
}
void DataManager::send_to_user(QString sendname, QString to_user, QString text)
{
QByteArray data, data_encrypt;
data = protocol->data_maker(Protocol::MESSAGE, sendname, to_user, text);
data_encrypt = protocol->data_encrypt(data);
tcpclient->sendToserver(data_encrypt);
qDebug() << "私发文本信息" << data;
}
void DataManager::send_file_to_all(QString sendname, QString filename, QByteArray file)
{
QByteArray data, data_encrypt;
data = protocol->data_maker(Protocol::FILE, sendname, filename, QString(file.toHex()));
data_encrypt = protocol->data_encrypt(data);
tcpclient->sendToserver(data_encrypt);
qDebug() << "群发文件";
}
void DataManager::send_file_private(QString sendname, QString filename, QByteArray file, QString name)
{
QByteArray data, data_encrypt;
data = protocol->data_maker(Protocol::FILE, name, sendname, filename, QString(file.toHex()));
data_encrypt = protocol->data_encrypt(data);
tcpclient->sendToserver(data_encrypt);
qDebug() << "私发文件";
}
*/

62
datamanager.h Normal file
View File

@ -0,0 +1,62 @@
#ifndef DATAMANAGER_H
#define DATAMANAGER_H
#include <QObject>
#include <QMessageBox>
#include <QJsonDocument>
#include "protocol.h"
#include "tcpclient.h"
class DataManager : public QObject
{
Q_OBJECT
public:
static DataManager* getInstance();
private:
explicit DataManager(QObject *parent = nullptr);
//static void recv_from_server(QString &peerAddress,quint16 peerPort,QByteArray &data);
//static Protocol *protocol;
//static DataManager *p_this;
Protocol *protocol;
TCPClient *tcpclient;
bool connect_flag = false;
signals:
void connect_to_server();
void disconnect_from_server();
void new_message();
void update_code(QString code);
void signin_response(bool result);
void signup_response(bool result);
void update_text(QString sendname,QString data);
void update_file(QString sendname,QString filename,QString file_data);
void update_file_private(QString sendname,QString filename,QString file_data);
void update_users(int count,QList<QString>online_users);
public slots:
/*******ui界面********/
void Register(QString username,QString password);
void signin_request(QString username,QString password);
/******WIDGET*****/
//void send_text(QString sendname,QString text);
//void send_to_user(QString sendname,QString to_user,QString text);
//void send_file_to_all(QString sendname,QString filename,QByteArray file);
//void send_file_private(QString sendname,QString filename,QByteArray file,QString name);
void update_namelist(QString username);
void account_cancellation(QString username);
void pick_up(QString code);
void parking();
/******TCPClient******/
void TCPClientConnected();
void TCPClientDisconnected();
void recv_from_server(QByteArray data);
};
#endif // DATAMANAGER_H

BIN
imgs/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

5
imgs/icon.qrc Normal file
View File

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file>icon.png</file>
</qresource>
</RCC>

232
login.cpp Normal file
View File

@ -0,0 +1,232 @@
#include "login.h"
#include "ui_login.h"
Login::Login(QWidget *parent) :
QWidget(parent),
ui(new Ui::Login)
{
ui->setupUi(this);
this->setWindowIcon(QIcon(":/icon.png"));
this->setTabOrder(ui->lineEdit_username,ui->lineEdit_password);
this->setTabOrder(ui->lineEdit_password,ui->btn_signin);
//this->setWindowFlags(Qt::FramelessWindowHint); //无边框
//this->setAttribute(Qt::WA_TranslucentBackground);
ui->btn_signin->installEventFilter(this);
/********datamanager********/
datamanager = DataManager::getInstance();
connect(datamanager,&DataManager::signin_response,this,&Login::signin_response);
connect(datamanager,&DataManager::signup_response,this,&Login::signup_response);
connect(datamanager,&DataManager::connect_to_server,this,&Login::connected);
connect(datamanager,&DataManager::disconnect_from_server,this,&Login::disconnected);
connect(this,&Login::signin_request,datamanager,&DataManager::signin_request);
connect(this,&Login::Register,datamanager,&DataManager::Register);
}
Login::~Login()
{
}
/***************************************SLOTS************************************/
void Login::on_btn_signin_clicked()
{
this->zoom_down(ui->btn_signin);
this->zoom_up(ui->btn_signin);
if(connect_flag == true)
{
user = ui->lineEdit_username->text();
passwd = ui->lineEdit_password->text();
if(user.isEmpty() || passwd.isEmpty())
{
QMessageBox::warning(this,tr("错误"),tr("用户名和密码不能为空!"));
return;
}
emit signin_request(user,passwd);
}
else
{
QMessageBox::warning(this, "登录失败", "尚未连接服务器!");
return;
}
}
void Login::on_btn_signup_clicked()
{
this->zoom_down(ui->btn_signup);
this->zoom_up(ui->btn_signup);
signup = new Signup();
connect(signup,&Signup::show_login_ui,this,&Login::show_login_ui);
connect(signup,&Signup::Register,this,&Login::slot_Register);
this->hide();
signup->show();
}
void Login::on_close_btn_clicked()
{
this->close();
}
void Login::show_login_ui()
{
this->show();
}
//等待服务器验证登陆数据
void Login::signin_response(bool result)
{
if(result == true)
{
mainwidget = new Widget();
connect(mainwidget,&Widget::account_cancellation,datamanager,&DataManager::account_cancellation);
connect(datamanager,&DataManager::disconnect_from_server,mainwidget,&Widget::disconnect_form_server);
connect(mainwidget,&Widget::exit_client,this,&Login::exit_client);
connect(mainwidget, &Widget::parking, datamanager, &DataManager::);
connect(mainwidget, &Widget::pick_up, datamanager, &DataManager::);
this->hide();
mainwidget->show();
}
else
{
QMessageBox::warning(this,tr("登录失败"),tr("用户名或密码错误!"));
}
}
//等待服务器注册数据
void Login::signup_response(bool result)
{
if(result == true)
{
QString information = QString("请妥善保存您的用户名和密码!");
QMessageBox::information(signup,tr("注册成功"),information);
signup->close();
this->show();
}
else
{
QMessageBox::warning(signup,tr("错误"),tr("注册失败,请重试!"));
}
}
//注册界面按下注册按键
void Login::slot_Register(QString username,QString password)
{
if(connect_flag == false)
{
QMessageBox::warning(signup, "注册失败", "尚未连接服务器!请连接服务器后重试");
return;
}
emit Register(username,password);
}
//连接上服务器
void Login::connected()
{
qDebug() << "connect to server";
connect_flag = true;
}
//未连上服务器或服务器断开
void Login::disconnected()
{
qDebug() << "disconnect from server";
connect_flag = false;
}
void Login::exit_client()
{
this->close();
}
/*****************************Others******************************/
void Login::zoom_down(QPushButton* btn)
{
QScopedPointer<QPropertyAnimation> animalton(new QPropertyAnimation(btn,"geometry"));
//设置间隔时间
animalton->setDuration(200);
//设置起始位置
animalton->setStartValue(QRect(btn->x(),btn->y(),btn->width(),btn->height()));
//设置结束位置
animalton->setEndValue(QRect(btn->x(),btn->y()+5,btn->width(),btn->height()));
//设置动画曲线
animalton->setEasingCurve(QEasingCurve::OutBounce);
animalton->start();
}
void Login::zoom_up(QPushButton* btn)
{
QScopedPointer<QPropertyAnimation>animalton(new QPropertyAnimation(btn,"geometry"));
animalton->setDuration(200);
animalton->setStartValue(QRect(btn->x(),btn->y()+5,btn->width(),btn->height()));
animalton->setEndValue(QRect(btn->x(),btn->y(),btn->width(),btn->height()));
animalton->setEasingCurve(QEasingCurve::OutBounce);
animalton->start();
}
void Login::new_closebutton(QPushButton* btn, QString position,QSize size)
{
QPixmap pixmap;
pixmap.load(position);
btn->setIconSize(size);
btn->setStyleSheet("QPushButton{border-width: 1px;border-style: solid;border-radius:15px;background-color: rgb(64, 145, 252);}"
"QPushButton:hover{background-color:#999999;}");
//设置图标
btn->setIcon(pixmap);
}
bool Login::eventFilter(QObject *target, QEvent *event)
{
if(target == ui->btn_signin) //可替换
{
if(event->type() == QEvent::KeyPress)//回车键
{
QKeyEvent *k = static_cast<QKeyEvent *>(event);
if(k->key() == Qt::Key_Return || k->key() == Qt::Key_Enter)
{
on_btn_signin_clicked(); //替换为需要响应的函数事件,以这里的按钮为例
return true;
}
}
}
return QWidget::eventFilter(target,event);
}
void Login::mousePressEvent(QMouseEvent *event)
{
if (event->buttons() == Qt::LeftButton)
{
point = event->pos();
}
}
void Login::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() == Qt::LeftButton)
{
//当窗口最大化或最小化时也不进行触发
if (Login::isMaximized() || Login::isMinimized())
{
return;
}
else
{
//当在按钮之类需要鼠标操作的地方不进行触发(防误触)
if (ui->btn_signin->underMouse() || ui->btn_signup->underMouse())
{
return;
}
else
{
Login::move(Login::mapToGlobal(event->pos() - point));
}
}
}
event->accept();
}

67
login.h Normal file
View File

@ -0,0 +1,67 @@
#ifndef LOGIN_H
#define LOGIN_H
#include <QWidget>
#include <QEvent>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QPushButton>
#include <QMainWindow>
#include <QPixmap>
#include <QMessageBox>
#include <QDebug>
#include <QGraphicsDropShadowEffect>
#include <QPropertyAnimation>
#include <QPainter>
#include <QMovie>
#include "datamanager.h"
#include "signup.h"
#include "widget.h"
namespace Ui {class Login;}
class Login : public QWidget
{
Q_OBJECT
public:
explicit Login(QWidget *parent = nullptr);
~Login();
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
signals:
void signin_request(QString username,QString password);
void Register(QString username,QString password);
private slots:
void on_btn_signin_clicked();
void on_btn_signup_clicked();
void on_close_btn_clicked();
void signin_response(bool result);
void signup_response(bool result);
void show_login_ui();
void slot_Register(QString username,QString password);
void connected();
void disconnected();
void exit_client();
private:
Ui::Login *ui;
QPoint point;
QString user,passwd;
static Login login_instance;
QPointer<Login> login;
QPointer<Signup> signup;
QPointer<Widget> mainwidget;
QPointer<DataManager> datamanager;
bool connect_flag = false;
void new_closebutton(QPushButton* btn, QString position,QSize size);
void zoom_up(QPushButton* btn);
void zoom_down(QPushButton* btn);
bool eventFilter(QObject *target, QEvent *event);
};
#endif // LOGIN_H

155
login.ui Normal file
View File

@ -0,0 +1,155 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Login</class>
<widget class="QWidget" name="Login">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>438</width>
<height>609</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QPushButton" name="btn_signup">
<property name="geometry">
<rect>
<x>250</x>
<y>370</y>
<width>79</width>
<height>40</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>40</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">QPushButton
{background-color:qlineargradient(spread:pad, x1:0, y1:1, x2:0, y2:0,
stop:1 rgba(64, 145, 252, 255),
stop:0 rgba(220, 255, 255, 255));
color: rgb(255, 255, 255);
border:0px groove gray;
border-radius:7px;
padding:2px 4px;
font: 14pt &quot;Candara&quot;;}
QPushButton:pressed
{background-color:#999999;}</string>
</property>
<property name="text">
<string>Sign up</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_username">
<property name="geometry">
<rect>
<x>70</x>
<y>230</y>
<width>289</width>
<height>45</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>45</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(247, 247, 247);
border:1px groove gray;border-radius:
7px;padding:2px 4px;
font: 12pt &quot;Candara&quot;;</string>
</property>
<property name="placeholderText">
<string>Please input your ID</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>120</x>
<y>160</y>
<width>191</width>
<height>51</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font: 87 20pt &quot;Arial Black&quot;;
background:transparent;</string>
</property>
<property name="text">
<string>Login Now</string>
</property>
</widget>
<widget class="QPushButton" name="btn_signin">
<property name="geometry">
<rect>
<x>100</x>
<y>370</y>
<width>71</width>
<height>40</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>40</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">QPushButton
{background-color:qlineargradient(spread:pad, x1:0, y1:1, x2:0, y2:0,
stop:1 rgba(64, 145, 252, 255),
stop:0 rgba(220, 255, 255, 255));
color: rgb(255, 255, 255);
border:0px groove gray;
border-radius:7px;
padding:2px 4px;
font: 14pt &quot;Candara&quot;;}
QPushButton:pressed
{background-color:#999999;}</string>
</property>
<property name="text">
<string>Sign in</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_password">
<property name="geometry">
<rect>
<x>70</x>
<y>290</y>
<width>289</width>
<height>45</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>45</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(247, 247, 247);
border:1px groove gray;border-radius:
7px;padding:2px 4px;
font: 12pt &quot;Candara&quot;;</string>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="placeholderText">
<string>Please input your password</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

12
main.cpp Normal file
View File

@ -0,0 +1,12 @@
#include "login.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
QApplication a(argc, argv);
Login w;
w.show();
return a.exec();
}

148
protocol.cpp Normal file
View File

@ -0,0 +1,148 @@
#include "protocol.h"
#include <QJsonDocument>
#include <QJsonArray>
Protocol Protocol::protocol_instance;
Protocol::Protocol(QObject *parent)
: QObject{parent}
{
}
Protocol::~Protocol()
{
}
Protocol* Protocol::getInstance()
{
return &protocol_instance;
}
QByteArray Protocol::data_builder(QList<any_types> &args)
{
QJsonObject data;
switch(args[0].get_data_types())
{
case MESSAGE:
{
data.insert("type","message");
data.insert("sendname",args[1].get_string());
data.insert("data",args[2].get_string());
break;
}
case CODE:
{
data.insert("type","code");
data.insert("action",args[1].get_string());
data.insert("data",args[2].get_string());
}
case REQUEST:
{
data.insert("type","request");
data.insert("action",args[1].get_string());
QList<QString> content = args[2].get_list();
QJsonObject json_content;
for (int i=0; i<content.length(); i+=2)
json_content.insert(content[i],content[i+1]);
data.insert("content",json_content);
break;
}
case ONLINEUSERS:
{
data.insert("type","online_users");
data.insert("count",args[1].get_int());
QList<QString> users = args[2].get_list();
QJsonArray json_users;
for (auto &user:users)
json_users.append(user);
data.insert("users",json_users);
break;
}
case RESPONSE:
{
data.insert("type","response");
data.insert("action",args[1].get_string());
QList<QString> content = args[2].get_list();
QJsonObject json_content;
for (int i=0; i<content.length(); i+=2)
json_content.insert(content[i],content[i+1]);
data.insert("content",json_content);
break;
}
default:
break;
}
QJsonDocument data_doc(data);
return data_doc.toJson(QJsonDocument::Compact)+'\n';
}
QPair<Protocol::data_types,QJsonObject> Protocol::data_parser(QByteArray data)
{
QJsonDocument json_data = QJsonDocument::fromJson(data);
if (json_data["type"] == "message")
return qMakePair(MESSAGE,json_data.object());
else if (json_data["type"] == "line")
return qMakePair(CODE,json_data.object());
else if (json_data["type"] == "request")
return qMakePair(REQUEST,json_data.object());
else if (json_data["type"] == "online_users")
return qMakePair(ONLINEUSERS,json_data.object());
else if (json_data["type"] == "response")
return qMakePair(RESPONSE,json_data.object());
else
return qMakePair(RESPONSE,json_data.object());
}
/******************************加解密部分************************************/
QByteArray Protocol::XOR_En_Decrypt(QByteArray src)
{
QByteArray result;
for(auto &i:src)
result.append(i ^ cipher_word);
return result;
}
QByteArray Protocol::Upper_Lower_En_Decrypt(QString src)
{
QByteArray result;
for(auto &i:src)
{
if(i.isUpper())
{
QChar word = i.toLower();
result.append(word.toLatin1());
}
else if (i.isLower())
{
QChar word = i.toUpper();
result.append(word.toLatin1());
}
else
result.append(i.toLatin1());
}
return result;
}
QByteArray Protocol::data_encrypt(QByteArray src)
{
QByteArray en_base64 = src.toBase64();
QByteArray result = Upper_Lower_En_Decrypt(en_base64);
return XOR_En_Decrypt(result);
}
QByteArray Protocol::data_decrypt(QByteArray src)
{
QByteArray result = XOR_En_Decrypt(src);
//qDebug() << result;
result = Upper_Lower_En_Decrypt(result);
//qDebug() << result;
return QByteArray::fromBase64(result);
}
void Protocol::set_data_cipher_word(char word)
{
cipher_word = word;
}

59
protocol.h Normal file
View File

@ -0,0 +1,59 @@
#ifndef PROTOCOL_H
#define PROTOCOL_H
#include <QObject>
#include <QJsonObject>
class Protocol : public QObject
{
Q_OBJECT
public:
static Protocol* getInstance();
template<typename Type, typename ...Args>
QByteArray data_maker(Type type, Args ...args)
{
QList<any_types> args_list;
args_list.append(any_types(type));
(void)std::initializer_list <int> {(args_list.append(any_types(args)),0)...};
return data_builder(args_list);
};
enum data_types {MESSAGE,CODE,REQUEST,ONLINEUSERS,RESPONSE};
QPair<data_types,QJsonObject> data_parser(QByteArray data);
QByteArray data_encrypt(QByteArray src);
void set_data_cipher_word(char word);
QByteArray data_decrypt(QByteArray src);
private:
char cipher_word = 'G';
struct any_types {
enum type {String, Bool, Int, Data_types, List};
any_types(int e) { m_data.INT = e; m_type = Int;}
any_types(QString e) { m_data.STRING = e; m_type = String;}
any_types(QList<QString> e) { m_data.LIST = e; m_type = List;}
any_types(bool e) { m_data.BOOL = e; m_type = Bool;}
any_types(data_types e) { m_data.DATA_TYPES = e; m_type = Data_types;}
type get_type() const { return m_type; }
int get_int() const { return m_data.INT; }
bool get_bool() const { return m_data.BOOL; }
data_types get_data_types() const { return m_data.DATA_TYPES; }
QString get_string() const { return m_data.STRING; }
QList<QString> get_list() const { return m_data.LIST; }
private:
type m_type;
struct {
int INT;
bool BOOL;
QString STRING;
QList<QString> LIST;
data_types DATA_TYPES;
} m_data;
};
static Protocol protocol_instance;
explicit Protocol(QObject *parent = nullptr);
~Protocol();
QByteArray data_builder(QList<any_types> &args);
QByteArray XOR_En_Decrypt(QByteArray src);
QByteArray Upper_Lower_En_Decrypt(QString src);
signals:
};
#endif // PROTOCOL_H

92
signup.cpp Normal file
View File

@ -0,0 +1,92 @@
#include "signup.h"
#include "ui_signup.h"
#include <QPointer>
Signup::Signup(QWidget *parent) : QWidget(parent),
ui(new Ui::Signup)
{
ui->setupUi(this);
}
Signup::~Signup()
{
delete ui;
}
//返回登录按钮
void Signup::on_btn_return_clicked()
{
this->close();
emit show_login_ui();
}
//注册按钮
void Signup::on_btn_sure_clicked()
{
QString username = ui->lineEdit_username->text();
QString password = ui->lineEdit_passwd->text();
QString surepass = ui->lineEdit_surepasswd->text();
if (username.isEmpty() || password.isEmpty() || surepass.isEmpty())
{
QMessageBox::warning(this, "注册失败", "输入不能为空!");
}
else
{
if (password == surepass)
{
emit Register(username,password);
}
else
{
QMessageBox::information(this, "用户注册", "两次密码输入不一致!");
}
}
}
void Signup::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing); // 反锯齿;
painter.setPen(Qt::transparent);
QRect rect = this->rect(); // rect为绘制大小
rect.setWidth(rect.width() - 1);
rect.setHeight(rect.height() - 1);
painter.drawRoundedRect(rect, 10, 10); // 10为圆角角度
}
void Signup::mousePressEvent(QMouseEvent *event)
{
if (event->buttons() == Qt::LeftButton)
{
point = event->pos();
}
}
void Signup::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() == Qt::LeftButton)
{
//当窗口最大化或最小化时也不进行触发
if (Signup::isMaximized() || Signup::isMinimized())
{
return;
}
else
{
//当在按钮之类需要鼠标操作的地方不进行触发(防误触)
if (ui->btn_sure->underMouse() || ui->btn_return->underMouse())
{
return;
}
else
{
Signup::move(Signup::mapToGlobal(event->pos() - point)); //移动
}
}
}
event->accept();
}

44
signup.h Normal file
View File

@ -0,0 +1,44 @@
#ifndef SIGNUP_H
#define SIGNUP_H
#include <QWidget>
#include <QPixmap>
#include <QMessageBox>
#include <QDebug>
#include <QGraphicsDropShadowEffect>
#include <QEvent>
#include <QPainter>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QMovie>
#include <QString>
namespace Ui {
class Signup;
}
class Signup : public QWidget
{
Q_OBJECT
public:
explicit Signup(QWidget *parent = nullptr);
~Signup();
void paintEvent(QPaintEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
signals:
void Register(QString username,QString password);
void show_login_ui();
private slots:
void on_btn_sure_clicked();
void on_btn_return_clicked();
private:
Ui::Signup *ui;
QPoint point;
};
#endif // SIGNUP_H

198
signup.ui Normal file
View File

@ -0,0 +1,198 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Signup</class>
<widget class="QWidget" name="Signup">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>438</width>
<height>609</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>80</x>
<y>90</y>
<width>161</width>
<height>31</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font: 87 20pt &quot;Arial Black&quot;;</string>
</property>
<property name="text">
<string>Hello</string>
</property>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>80</x>
<y>190</y>
<width>271</width>
<height>344</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label_6">
<property name="styleSheet">
<string notr="true">font: 10.5pt &quot;Arial&quot;;</string>
</property>
<property name="text">
<string>Username</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_username">
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">font: 12pt &quot;Arial&quot;;</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="styleSheet">
<string notr="true">font: 11pt &quot;Arial&quot;;</string>
</property>
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_passwd">
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">font: 12pt &quot;Arial&quot;;</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_8">
<property name="styleSheet">
<string notr="true">font: 10.5pt &quot;Arial&quot;;</string>
</property>
<property name="text">
<string>Ensure your password</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_surepasswd">
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">font: 12pt &quot;Arial&quot;;</string>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btn_sure">
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(29, 123, 255);
color: rgb(255, 255, 255);
font: 26 10pt &quot;Bahnschrift Light&quot;;</string>
</property>
<property name="text">
<string>Sure</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_return">
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(29, 123, 255);
color: rgb(255, 255, 255);
font: 26 10pt &quot;Bahnschrift Light&quot;;</string>
</property>
<property name="text">
<string>Return login</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>80</x>
<y>120</y>
<width>301</width>
<height>51</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font: 87 20pt &quot;Arial Black&quot;;</string>
</property>
<property name="text">
<string>Welcome to us!</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

106
tcpclient.cpp Normal file
View File

@ -0,0 +1,106 @@
#include "tcpclient.h"
#include <QHostAddress>
#include <QTime>
#include <QCoreApplication>
using namespace std;
TCPClient TCPClient::tcpclient_instance;
QTcpSocket TCPClient::socket;
TCPClient::TCPClient(QObject *parent)
: QObject{parent}
{
}
TCPClient::~TCPClient()
{
}
TCPClient* TCPClient::getInstance()
{
return &tcpclient_instance;
}
void TCPClient::configAndrun()
{
qDebug() << "进入configandrun";
socket.setSocketOption(QAbstractSocket::KeepAliveOption,1);
socket.connectToHost(server_ip, server_port);
connect(&socket,&QTcpSocket::connected,this,&TCPClient::connected);
connect(&socket,&QTcpSocket::disconnected,this,&TCPClient::disconnected);
connect(&socket,&QTcpSocket::readyRead,this,&TCPClient::readSocket);
}
void TCPClient::sendToserver(QByteArray &data)
{
if (socket.isOpen())
{
socket.write(data);
socket.waitForBytesWritten(2000);
}
}
void TCPClient::setServer(QString IP, quint16 port)
{
server_ip = IP;
server_port = port;
}
void TCPClient::connected()
{
emit TCPClientConnected();
qDebug() << "emit TCPClientConnected successfully";
QString addr_t = socket.peerAddress().toString();
QByteArray addr = addr_t.toLocal8Bit();
printf("Connected to server at %.*s:%d.\n",addr.size(),addr.data(),socket.peerPort());
}
void TCPClient::disconnected()
{
emit TCPClientDisconnected();
qDebug() << "emit TCPClientDisconnected successfully";
printf("Disconnected from server.\n");
}
void TCPClient::readSocket()
{
QByteArray recv;
while(socket.bytesAvailable())//循环接收
{
recv += socket.readAll();
if (!socket.waitForReadyRead(_timeout))//超时停止接收
{
/*QString error = sock->errorString();
string error_t = error.toStdString();
log_w("error:%d: %.*s", sock->error(),error_t.length(), error_t.data());*/
break;
}
}
QString ip = socket.peerAddress().toString();
string ip_t = ip.toStdString();
printf("TCPC: Recvd from %.*s:%d\n", ip_t.length(), ip_t.data(), socket.peerPort());
printf("TCPC Message:%.*s\n",recv.size(),(char *)recv.data());
if (_callback != nullptr)
_callback(ip, socket.peerPort(),recv);
emit recv_data(recv);
}
void TCPClient::setTimeOut(int timeout)
{
_timeout = timeout;
}
void TCPClient::setCallBack(void (*callback)(QString &mac, quint16 port, QByteArray &data))
{
_callback = callback;
}
void TCPClient::_sleep(int msec)
{
QTime dieTime = QTime::currentTime().addMSecs(msec);
while( QTime::currentTime() < dieTime )
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}

41
tcpclient.h Normal file
View File

@ -0,0 +1,41 @@
#ifndef TCPCLIENT_H
#define TCPCLIENT_H
#include <QObject>
#include <QTcpServer>
#include <QTcpSocket>
class TCPClient : public QObject
{
Q_OBJECT
public:
static TCPClient* getInstance();
static void sendToserver(QByteArray &data);
void configAndrun();
void setCallBack(void (*callback)(QString &ip, quint16 port,QByteArray &data));
void setServer(QString IP, quint16 port);
void setTimeOut(int timeout);
private slots:
void readSocket();
void connected();
void disconnected();
private:
explicit TCPClient(QObject *parent = nullptr);
~TCPClient();
static void _sleep(int msec);
static QTcpSocket socket;
static TCPClient tcpclient_instance;
int _timeout = 20;
QString server_ip = "127.0.0.1";
quint16 server_port = 7890;
bool has_found = false;
void (*_callback) (QString &ip, quint16 port,QByteArray &data)=nullptr;
signals:
void TCPClientConnected();
void TCPClientDisconnected();
void recv_data(QByteArray data);
};
#endif // TCPCLIENT_H

136
widget.cpp Normal file
View File

@ -0,0 +1,136 @@
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
ui->log->setEnabled(false);
//连接mqtt服务器端口1883
mqtt_client = new QMqttClient(this);
mqtt_client->setHostname(QHostAddress(QHostAddress::LocalHost).toString());
mqtt_client->setPort(port);
mqtt_client->setClientId("mobile");
mqtt_client->setUsername("Phone");
mqtt_client->setPassword("Phone");
mqtt_client->connectToHost();
connect(mqtt_client, &QMqttClient::disconnected, this, &Widget::disconnected_handler);
connect(mqtt_client, &QMqttClient::messageReceived, this, &Widget::received_handler);
connect(mqtt_client, &QMqttClient::pingResponseReceived, this, &Widget::pingresp_handler);
connect(mqtt_client, &QMqttClient::connected, this, &Widget::connected_handler);
connect(mqtt_client, &QMqttClient::errorChanged, this, &Widget::error_handler);
connect(mqtt_client, &QMqttClient::stateChanged, this, &Widget::state_handler);
connect(ui->pushButton, &QPushButton::clicked, [=]() {
ui->stackedWidget->setCurrentIndex(0);
});
connect(ui->pushButton_2, &QPushButton::clicked, [=]() {
ui->stackedWidget->setCurrentIndex(1);
});
}
Widget::~Widget()
{
delete ui;
}
//点击存车按钮
void Widget::on_pushButton_3_clicked()
{
emit parking();
}
//点击取车按钮
void Widget::on_pushButton_4_clicked()
{
emit pick_up(ui->code->toPlainText());
}
void Widget::connected_handler()
{
const QString content = QDateTime::currentDateTime().toString()
+"\n"
+"MQTT服务器已连接上\n";
ui->log->insertPlainText(content);
sub = mqtt_client->subscribe(topic,1);
if (sub)
{
const QString content = QDateTime::currentDateTime().toString()
+"\n"
+"Topic: "+ topic + QLatin1Char('\n')
+"Qos: "+QLatin1Char(sub->qos()+'0')+QLatin1Char('\n')+
"已订阅\n";
ui->log->insertPlainText(content);
}
else
{
const QString content = QDateTime::currentDateTime().toString()
+"\n"
+"Topic: "+ topic + QLatin1Char('\n')
+"Qos: "+QLatin1Char(sub->qos()+'0')+QLatin1Char('\n')+
"订阅失败,请检查网络情况\n";
ui->log->insertPlainText(content);
}
}
void Widget::disconnected_handler()
{
const QString content = QDateTime::currentDateTime().toString()
+"\n"
+"MQTT服务器已断开\n";
ui->log->insertPlainText(content);
}
void Widget::received_handler(const QByteArray &message, const QMqttTopicName &topic)
{
const QString content = QDateTime::currentDateTime().toString()
+"\n"
+"Topic: "+topic.name()+ QLatin1Char('\n')
+"Message: "+message+ QLatin1Char('\n')+
+"Qos: "+QLatin1Char(sub->qos()+'0')+QLatin1Char('\n');
ui->log->insertPlainText(content);
}
void Widget::pingresp_handler()
{
const QString content = QDateTime::currentDateTime().toString()
+ QLatin1Char('\n')
+ QLatin1String("MQTT Pong!")
+ QLatin1Char('\n');
ui->log->insertPlainText(content);
}
void Widget::state_handler()
{
const QString content = QDateTime::currentDateTime().toString()
+ QLatin1Char('\n')
+ ":MQTT Client State Change"
+ QString::number(mqtt_client->state())
+ u'\n';
ui->log->insertPlainText(content);
}
void Widget::error_handler(const QMqttClient::ClientError error)
{
const QString content = QDateTime::currentDateTime().toString()
+"\n"
+"Error: "+ QString::number(static_cast<int>(error));
ui->log->insertPlainText(content);
}
void Widget::disconnect_form_server()
{
QMessageBox::critical(this,"连接超时","请检查您的网络连接!");
qApp->quit();
}

50
widget.h Normal file
View File

@ -0,0 +1,50 @@
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QStackedWidget>
#include <QMessageBox>
#include <QtMqtt/QMqttClient>
#include "datamanager.h"
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
void connected_handler();
void disconnected_handler();
void received_handler(const QByteArray &message, const QMqttTopicName &topic);
void pingresp_handler();
void state_handler();
void error_handler(const QMqttClient::ClientError error);
signals:
void account_cancellation(QString username);
void exit_client();
void parking();
void pick_up(QString code);
public slots:
void on_pushButton_3_clicked();
void on_pushButton_4_clicked();
void disconnect_form_server();
private:
Ui::Widget *ui;
QMqttClient *mqtt_client;
QMqttSubscription* sub = nullptr;
QString topic = "/car";
quint16 port = 1883;
};
#endif // WIDGET_H

159
widget.ui Normal file
View File

@ -0,0 +1,159 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Widget</class>
<widget class="QWidget" name="Widget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>489</width>
<height>718</height>
</rect>
</property>
<property name="windowTitle">
<string>Widget</string>
</property>
<widget class="QStackedWidget" name="stackedWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>501</width>
<height>661</height>
</rect>
</property>
<widget class="QWidget" name="page">
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>40</x>
<y>50</y>
<width>251</width>
<height>71</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>20</pointsize>
</font>
</property>
<property name="text">
<string>欢迎来到停车场</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>50</x>
<y>150</y>
<width>311</width>
<height>71</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="text">
<string>放置驱车码</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_3">
<property name="geometry">
<rect>
<x>90</x>
<y>390</y>
<width>93</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>存车</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_4">
<property name="geometry">
<rect>
<x>280</x>
<y>390</y>
<width>93</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>取车</string>
</property>
</widget>
<widget class="QTextEdit" name="code">
<property name="geometry">
<rect>
<x>90</x>
<y>266</y>
<width>281</width>
<height>51</height>
</rect>
</property>
</widget>
</widget>
<widget class="QWidget" name="page_2">
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>60</x>
<y>60</y>
<width>241</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>18</pointsize>
</font>
</property>
<property name="text">
<string>尊敬的用户您好</string>
</property>
</widget>
<widget class="QTextBrowser" name="log">
<property name="geometry">
<rect>
<x>60</x>
<y>140</y>
<width>341</width>
<height>381</height>
</rect>
</property>
</widget>
</widget>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>70</x>
<y>660</y>
<width>93</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>主页</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
<property name="geometry">
<rect>
<x>310</x>
<y>660</y>
<width>93</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>用户</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>