当前位置:网站首页>Real-time waveform display of CAN communication data based on QT (serial eight) ==== "Sub function or new class calls ui control"
Real-time waveform display of CAN communication data based on QT (serial eight) ==== "Sub function or new class calls ui control"
2022-07-30 07:13:00 【transparent light】
Foreword
After the data in the main program is transferred to the new class (here is the thread, others are similar), you need to draw in it, so you need to call the controls of the ui interface.I searched for many methods on the Internet, and tried them one by one, but there was no way to achieve it perfectly, either here or there.So I wonder if I used a fake QT myself, why, I don't know, it just can't come out with reference to their method.Discuss with experts and combine the online examples to come up with a solution that can be solved, which is very easy to use, and is consistent with the method above, which is very convenient.
Part 1: Sub-functions or other classes call ui controls
The first step: Create a control in the ui of the main function. The control in qcustomplot is used here. If this part will not be added, you can refer to the method in the previous article. It is very convenient and simple, and the steps are very detailed..An improved widget is used here, now the qcustomplot class.The name is PLOTVSAMP.In fact, it is also possible to directly pull a button. I have tested this, and it works.
Step 2: In the main function, define the function.The first sentence has been introduced above, define a new class in the main function, and this class name is also its newly created class name.It doesn't matter which parent class he is a subclass of.My parent class here is the thread QThread class.How to create a reference to the previous article, written in great detail.
mythread = new datadeal(this);mythread->SetMainWindow( this );
Step 3: Change the private members in the main function h file to public members, this location should be easy to find.Prepare for the new class to call the UI controls.
public:Ui::MainWindow *ui;
Step 4: In the second step, the function has been set, and there is no function body. Add the function declaration and body to the h file of the new class, and define the pointer of the main window here (not very suitable, just look at it this way, it is calledThere is a little problem, easy to understand), in fact, in the second step, this refers to the pointer in the mainwindow, which is put here as a formal parameter. This is the entry of the mainwindow, which is defined as pwinmain.At the same time, assign this pointer to m_pwinmain, so that the pointer of the main window is given to the pointer in the new class.
public:void SetMainWindow( MainWindow* pWinMain ){m_pWinMain = pWinMain;}
Step 5: The pointer to the main program of the new class already exists, and the position where the pointer is defined is the same as that of the main program.
private:MainWindow* m_pWinMain;
Step 6: Explain the logic in popular words again: building bridges
(1) There is a ravine between the two pieces of land, and a bridge must be built to communicate between the two places;
(2) Build a bridge pier first on the first piece of land, and build a bridge pier on the second piece of land;
(3) The bridge piers are connected by bridges.
(4) The train on this side of the bridge and the train on the other side of the bridge exchange carriages for delivery, and the car on this side exchanges delivery with the car on the other side.
Similar to:
(1) The class of mainwindow and the new class defined are equivalent to two fields;
(2) Trains and cars are equivalent to members of each class. If you want to deliver goods, you must be train-to-train and car-to-car.Cars are like ui controls, trains are like other defined variables;
(3) The two classes must have the same members, and there must be trains and cars on both sides.So the class of mainwindow must define a new class (step 2), and the new class must define the class of mainwindow (step 5);
(4) The setmainwindow defined by the mainwindow class is equivalent to a bridge pier, which is built first.
(5) The function in setmainwindow connects the two, which is the bridge (the fourth step).
In this way, the car in the new class can be delivered directly to the car (ui control) in the mainwindow.
Step 7: You can use m_p to associate the ui control, and then draw the picture again. See the previous article for the graph function and the like, which is very detailed.Of course, it can also be other controls. I have tried changing the size and text of the button, and they can all be used.
m_pWinMain->ui->PLOTVSAMP->graph(0)->setData(gvUTCms,gvUTCms);m_pWinMain->ui->PLOTVSAMP->replot();
Part II: Summary
The overall steps are the same as the logic in "QT-based Real-time Waveform Display of CAN Communication Data (Serial Seven) ==== "Data Transmission of Different Classes", which should be well understood.
There are milliseconds in the CAN frame, send the ms number to the new class (thread), start the thread in the main program, and draw a picture, you can get the correct graphics.The left side is the CAN frame display program made in the previous article, and the right side waveform is the drawing in the UI interface in the new class.
Note: Since the time when the small partners need the source code is different, it is too troublesome to log in to the mailbox interface, so a subscription number has been established. If you have any questions or need the source code, you can add a subscription number. After leaving a message, the source code will be sent or anyQuestions can be left in the comments, and we will actively solve the problems raised.
边栏推荐
- R语言 生态环境领域应用
- 华秋第八届硬创赛与安创加速器达成战略合作,助力硬科技项目成长
- Basic application of XMLBean
- Antd 树拖拽一些细节,官网没有,摸坑篇
- 三种内核结构---宏内核、微内核、混合内核
- [Jiangsu University Self-Chemistry Association stm32F103c8t6] Notes [Introduction to 32 MCUs and Using TIM Output to Compare and Configure PWM]
- 干货:线上下单应知应会,快来了解下
- The application of Meta analysis in the field of ecological environment
- jvm之逃逸分析
- 边境的悍匪—机器学习实战:第十三章 使用TensorFlow加载和预处理数据
猜你喜欢
使用Dva项目作Antd的Demo
Generalized Focal Loss paper reading notes
How does MATLAB display nii file slice information in the image?
【江科大自化协stm32F103c8t6】笔记之【入门32单片机及GPIO初始化参数配置】
迪文串口屏幕制作(连载一)=====准备工作
求职准备知识点
与所有 ARM 工具、软件兼容?韦斯佰瑞这款MCU内核值得关注!
边境的悍匪—机器学习实战:第三章 分类
Application of remote sensing, GIS and GPS technology in hydrology, meteorology, disaster, ecology, environment and health
"R Language + Remote Sensing" Comprehensive Evaluation Method of Water Environment
随机推荐
Knowledge distillation method of target detection
openssl1.1.1ARM dual compilation
与所有 ARM 工具、软件兼容?韦斯佰瑞这款MCU内核值得关注!
【正点原子】sys.c、sys.h位带操作的简单应用
Massive remote sensing data processing and application of GEE cloud computing technology [basic, advanced]
联影医疗二面
超详细的PCB高可靠辨别方法
Kunlun State Screen Production (serialization 4) --- Basics (graphical setting and display, button lights)
爬2.12.6的Antd上传图片坑
“R语言+遥感”的水环境综合评价方法
动态规划入门 JS
How does MATLAB display nii file slice information in the image?
2021年软考中级过关
【江科大自化协stm32F103c8t6】笔记之【入门32单片机及EXTI外部中断初始化参数配置】
边境的悍匪—机器学习实战:第一章 机器学习的基础知识
Biome-BGC 生态系统模型与应用
Anaconda 安装低版本tensorflow
昆仑通态屏幕制作(连载3)---基础篇(按钮串口发送)
Kunlun State Screen Production (Serialization 5) --- Basics (serial port reception, text and light display)
survivor区对象何时进入老年代(深入理解jvm中表述不准确的地方)