In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the knowledge points of Qt project architecture". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "what are the knowledge points of Qt project architecture"!
(i) General rules
In addition to very small demo-level projects, other projects are recommended to use pri to store code files in different folders for unified management and search.
It is recommended that classes with the same type of function be put together uniformly. If the number of code files under this directory is too large, it is also recommended to split multiple directories for storage.
For example, for projects with 3-5 interfaces, a form.pri is unified to store these interfaces, and when the project becomes larger and larger, the interface may also need to be divided according to functions, for example, the system configuration form is placed in a directory, and the log management form is placed in a directory.
Many common functions, multiple projects will be used, you can consider packaging into pri form of modules, commonly known as wheels, constantly improve these wheels, multiple projects share the module, once BUG repair, only need to change one place on the line.
If the project is larger or the project team assigns different functions, you can consider the plug-in form. Plug-ins generally use two kinds: one is a plug-in in the form of a common dynamic library, which must be placed together with the main program; the other is a plug-in of the Qt mechanism, which is placed in a specified directory.
(ii) Global configuration file
The global configuration file management class appconfig.h is used to read and write the configuration file of the corresponding project.
The format can be ini, xml, json, etc., small projects suggest ini, how convenient to come, equivalent to mapping the value of the configuration file to the global variable.
If there are many configuration items in the configuration file, it is recommended to store them in groups for easy search, instead of putting them all in a large group.
When reading the configuration file, you can judge whether the configuration file exists, whether the configuration item is missing, etc. If there is a problem, you can regenerate the configuration file to avoid malicious deletion of the configuration file resulting in abnormal program operation.
When reading the configuration file, you can fill in the default value (the second parameter of the value method of the qt configuration file class QSettings, set.value("Hardware", App::Hardware)) to avoid failing to read the node at the initial time and causing the value of the configuration item not to meet the expected value type.
After reading the configuration file, you can re-judge whether the value of the configuration item meets the requirements, filter and correct the value, and prevent the abnormal value from being filled in after manually opening the configuration file. For example, the interval of the timer is 0, and the legal value should be corrected again.
Initial values with Chinese are wrapped in QString::fromUtf8, such as QString::fromUtf8("Administrator").
For configuration items with Chinese, the configuration file code to be set is utf-8, set. setInitiCodec ("utf-8").
(c) Global variables
The global variable management class appdata.h is used to set all global variables used in the project.
For example, whether the current user/system is locked, etc., so that the variable can be used at any coding position for judgment processing.
You can set the width and height of the navigation bar, button size, icon size and other variables in the UI interface here, and determine the resolution after the system starts to set different values.
(IV) Global event transfer processing
The global event relay processing class appevent.h is used to relay various events across multiple UIs and classes in the system.
This class must be a global singleton class for uniform global use.
For example, the parent of class a is b, the parent of class b is c, and now there is a signal to be sent to class d. In the case where there is no event relay processing, the method is to send a signal to b, b to c, c to d. If the parent nesting level is more and more complex, the code is more difficult to manage.
Send the signal of class a to appevent class, and then class d directly associates appevent class for processing.
The larger the project, the more necessary it will be to find event transfer processing, clear code, easy management.
(V) Global program initialization
The global program initialization class appinit.h is used to do some initialization after program startup.
Read configuration files.
Set global font.
To set up a global style sheet, it is recommended to read the general style sheet first, and then add the additional style sheet content to the later settings.
Set the project code.
Set translation files, you can load multiple, including qt built-in qt_zh_CN.qm, user's own translation files, etc.
Initialize random number seed.
Create new directories needed in the project to prevent files from being saved to directories without directories.
Initialize the database, including opening the database and loading basic data such as user tables, device tables, etc.
The startup log output class is used to start the log service.
The startup runtime logging class is used to record the start and end times of each software run.
Associative global event filters handle custom borderless UI dragging, global key handling, and more.
(6) Global general category
The debug log output class savelog.h is used to start the log service, which can output logs to a file or network printout.
The runtime logging class saveruntime.h is used to record the start and end times of each software run.
Graphic font class iconfont.h is used to set graphic font icons.
At this point, I believe everyone has a deeper understanding of "what are the knowledge points of Qt project architecture". Let's do it in practice! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.