当前位置:网站首页>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.

边栏推荐
猜你喜欢

边境的悍匪—机器学习实战:第四章 训练模型
![[Jiangsu University Automation Association stm32F103c8t6] Notes [Initial 32 MCU and EXTI External Interrupt Initialization Parameter Configuration]](/img/e5/87cf293ac3d0c613864e99a8fe9a47.png)
[Jiangsu University Automation Association stm32F103c8t6] Notes [Initial 32 MCU and EXTI External Interrupt Initialization Parameter Configuration]

QT连载2:基于QT和STM32H750的LORA试验平台(1)

OpenLayers (ol包),Vite显示地图(附源码)

R language application in the field of ecological environment

i++与 ++i 的区别

QT串口和CAN数据动态实时显示最后日志

使用Dva项目作Antd的Demo

干货 | 什么是FOC?一文带你看BLDC电机驱动芯片及解决方案

边境的悍匪—机器学习实战:第八章 降维
随机推荐
基于OpenCV的双目重建
Massive remote sensing data processing and application of GEE cloud computing technology [basic, advanced]
openssl 1.1.1编译语句
边境的悍匪—机器学习实战:第一章 机器学习的基础知识
【江科大自化协stm32F103c8t6】笔记之【入门32单片机及利用TIM输出比较配置PWM】
Analysis of domestic data exchange platforms
查看 word版本号
【正点原子】IIC的学习与使用(未完...)
关于报错vscode
动态规划入门 JS
User password encryption using Bcrypt instead of MD5, SHA1 and SHA256
边境的悍匪—机器学习实战:第十六章使用RNN和注意力机制进行自然语言处理
Antd简单启动一个企业级项目
服务器基础知识:包含基本概念,作用,服务器选择,服务器管理等(学习来自米拓建站)
JS的值和引用,复制和传递
边境的悍匪—机器学习实战:第七章 集成学习和随机森林
边境的悍匪—机器学习实战:第二章 端到端的机器学习项目
昆仑通态屏幕制作(连载1)---接触篇
华秋第八届硬创赛与安创加速器达成战略合作,助力硬科技项目成长
“R语言+遥感”的水环境综合评价方法