<>( one ) General rules

* Except for the tiny, tiny demo Out of level project , It is recommended to use for other projects pri Code files are stored in different categories and folders , Convenient for unified management and search .
* It is suggested that the classes of the same type of functions should be put together , If there are too many code files in this directory , It is also recommended to split multiple directories for storage .
*
For example 3-5 An interface project , Make a unified plan form.pri Store these interfaces , And as the project gets bigger and bigger , The interface may also need to be divided by function , For example, the system configuration window is placed in a directory , Log management form in a directory .
*
Many common functions , It will be used in many projects , We can consider packaging into pri Formal modules , Commonly known as the wheel , Constantly improve these wheels , Multiple projects share the module , Once met BUG repair , Just change one place .
*
If the project is larger or the project team is assigned different functions , Consider the plug-in form , Plug ins generally use two types , One is the plug-in in the form of ordinary dynamic library , Must be placed with the main program ; One is Qt Plug in of mechanism , Put it in the specified directory .
<>( two ) Global profile

Global profile management class appconfig.h Used to read and write the configuration file of the corresponding project .

* The format can be ini,xml,json etc. , Small project proposal ini, How is it convenient , It is equivalent to mapping the values of the configuration file to global variables .
* If there are many configuration items in the configuration file, it is recommended to store them in groups for easy searching , Not all in one big group .
* When reading the configuration file, you can judge whether the configuration file exists , Is the configuration item missing , If there is a problem, regenerate the configuration file , Avoid malicious deletion of configuration files, resulting in abnormal program operation .
* You can fill in the default value when reading the configuration file (qt Profile class QSettings Of value The second parameter of the method ,set.value(“Hardware”,
App::Hardware)), To avoid that the configuration item value does not conform to the expected value type because the node cannot be read at the initial time .
*
After reading the configuration file, you can re judge whether the value of the configuration item meets the requirements , Filter and correct the values , Prevent the configuration file from being opened artificially, and fill in the abnormal value after modification , For example, the interval of timer is 0, To correct the value set to legal again .
* Initial value with Chinese QString::fromUtf8 wrap up , such as QString::fromUtf8(“ administrators ”).
* For configuration items with Chinese, set the configuration file code to utf-8,set.setIniCodec(“utf-8”).
<>( three ) global variable

Global variable management class appdata.h Used to set all global variables used in the project .

* For example, the current user / Whether the system is locked, etc , In this way, the variable can be used in any coding position for judgment processing .
* You can UI The width and height of the navigation bar in the interface , Button size , The icon size and other variables are put here , After the system starts, judge the resolution to set different values .
<>( four ) Global event transfer processing

Global event transfer processing class appevent.h It is used to transfer all kinds of data across multiple channels in the system UI And events of multiple classes .

* This class must be a global singleton class , Easy to use globally .
*
For example, class a The parent of is b, class b The parent of is c, Now there's a signal for the class d, In the case of no event transfer processing, the method is to a Signal to b,b Send again c,c Send again d, If the parent class nested more levels, the more complex , The harder the code is to manage .
* Class a The signal is sent to appevent class , Then class d Direct connection appevent Class .
* The bigger the project , The more we find the necessity of event transfer processing , The code is clear , Convenient management .
<>( five ) Global program initialization

Global program initialization class appinit.h Used to do some initialization processing after the program starts .

* Read configuration file .
* Set global font .
* Set global style sheet , It is recommended to read the common style sheet first , Then add the extra style sheet content to the back and set it together .
* Set item code .
* Set up translation files , You can load multiple , include qt Built in qt_zh_CN.qm, User's own translation documents, etc .
* Initialize random number seed .
* Directory needed in new project , Prevent files from being saved to a directory without a directory .
* Initialize database , This includes opening the database , Loading basic data, such as user tables , Equipment list, etc .
* The start log output class is used to start the log service .
* The start run time record class is used to record the start time and end time of each software run .
* Associated global event filter handles custom borderless UI drag , Global key processing, etc .
<>( six ) Global general class

* Debug log output class savelog.h Used to start the log service , Log can be output to file or network printout .
* Runtime record class saveruntime.h Used to record the start time and end time of each software run .
* Graphic font class iconfont.h Used to set the graphic Font Icon .
<> To be updated continuously

Technology