当前位置:网站首页>QT based software framework design
QT based software framework design
2022-07-24 12:28:00 【Progress every day 2015】
1、 Introduction
Qt, In the understanding of many people, it is a framework for making interfaces , Only used for interface , The back end is often implemented by others . In my practice , I use both interface and back-end implementation Qt To implement the .
2、 Software layering
Generally speaking , Our software architecture will be very layered , Here we have three floors 了 , The layering is shown in the figure below :

2.1 GUI layer
Here we are based on Qt Of , So this layer is used Qt Class library to achieve , All the main interfaces will be from these three classes :QWiget,QMainWindow,QDialog One of them inherits , And in main Generate an instance in the function and show come out , Enter the main message loop . I am used to using QWiget, Don't use UI file , All interfaces are new come out , Then use code to layout .
2.2 Models layer
model Layer mainly realizes the business logic of our software , The modules here are reasonably divided according to the business logic of the whole software , Achieve the effect of high cohesion and loose coupling . Here we are concerned with one of these business logic classes , There? new There is a problem . Here's what I did : Make one bridge class , Let all business logic classes be in this bridge Instantiate in class .
2.3 Communication layer
In this layer, data collection is realized , signal communication The way There are many kinds , Serial port , There is a net port , Yes CAN Mouth, etc . The data received by this layer is sent to models Layer hair , User input is also sent to the actuator through this layer .
So this layer of classes , Where to instantiate ? I also choose bridge In class , such ,bridge Class is actually a class without any business functions , It only provides that various classes can interact with each other connect( Signal slot ) The carrier of .
3、 Lower floor and GUI Communication at the management level
thus , Our division GUI Class of layer ( Communication and module ) All in bridge Classes can communicate through the mechanism of signal slots . So how does our model match GUI To communicate ?
We can go through this bridge Class , Because of our other All classes are in bridge Class , So this class can have class references , We can do it in QWidget Pass a constructor in bridge Class pointer goes in , such , All our classes , Can be with GUI We're communicating .
4、 Run the architecture
When we have designed all levels of code , And know in that category , After that level is realized , We need to use threads to make the whole software run happily . This is what we want to say about the operation architecture .
generally speaking , We put all the communication All classes Will come out alone as a thread , such , It won't block GUI Threads , It can also respond faster to collect information and transmit control information to the lower computer .
therefore communication This floor , Generally, there are several threads in several ports . Of course, some lightweight ones can be combined in one thread .
bridge Class received GUI In the thread , Why do that , When our interface pops up , From you to model in get The latest value is displayed on the interface ,( It is also possible to use signal slots, but it will be more cumbersome ), So call get Methods , There is such a need , We'd better put all model All in one thread ——- namely GUI Threads .
In this way, the main framework of our small information acquisition and control system is built .
The last point to emphasize is : Recommended when using threads movetothread Methods . If you don't use this method , All instances must be in the thread run() In the function new come out , To ensure that the slot function of this class is executed in the message loop of this thread .
————————————————
Copyright notice : This paper is about CSDN Blogger 「amwha」 The original article of , follow CC 4.0 BY-SA Copyright agreement , For reprint, please attach the original source link and this statement .
Link to the original text :https://blog.csdn.net/amwha/article/details/73928281
边栏推荐
- Force deduction exercise - 29 complete the array as required
- QT notes - realize form adaptation
- Reserved instances & Savings Plans
- Native Crash的一切
- Detailed explanation of MSTP protocol for layer 3 switch configuration [Huawei ENSP experiment]
- 02 linear structure 2 multiplication and addition of univariate polynomials (linked list solution)
- Buckle practice - sum of 34 combinations
- 3、 Implementation principle of MFC message mapping mechanism
- Do you regret learning it?
- Wechat official account development: Material Management (temporary and permanent)
猜你喜欢

C Advanced - data storage

Source code analysis sentry user behavior record implementation process

高速成长的背后,华为云乌兰察布数据中心的绿色之道

The biggest crisis for testers in the workplace is not at the age of 30, but being laid off in middle age

Use and expansion of fault tolerance and fusing

QT notes - EventFilter event filter

如何最快找出复杂代码运行时的函数调用流程

Counter attack dark horse: devdbops training, give you the best courses!

4*4图片权重的收敛规则

微信公众号开发:素材管理(临时、永久)
随机推荐
突破内存墙能带来什么?看火山引擎智能推荐服务节支增效实战
VMware virtual machine and vSphere migrate to each other
Day5: construct program logic
三、MFC消息映射机制实现原理
【功能测试】项目的测试——登录和发布文章功能
微信小程序-绘制仪表盘
Script redis write project notes
Source code analysis sentry user behavior record implementation process
Overview of MES system equipment management (medium)
Open source DNS software powerdns BIND9 mydns
What is prescaler in STM32
[C and pointer Chapter 14] preprocessor
Try... Finally summary
A* and JPS
STM32——C语言基础
TypeNameExtractor could not be found
Implementing deep learning framework from zero -- further exploration of the implementation of multilayer bidirectional RNN
thinkphp 实现数据库备份
With the strong development of cloud native, how should enterprises seize business opportunities
[Commons beanautils topic] 004 beanautils topic