用qt creator画实时图像
来源:互联网 发布:七个魂器都是什么 知乎 编辑:程序博客网 时间:2024/06/06 18:15
我是看了http://blog.csdn.net/coekjin/article/details/52123877的文章,写的很详细,只是代码缺少注释,我这里给些注释,希望对大家有所帮助。
#include "widget.h"#include "ui_widget.h"#include <QVector>#include <QTime>#include <QTimer>Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ ui->setupUi(this); //头文件中声明了num[]和n,这里给出初始化 for(int i=0;i<10;i++) { num[i] = 0; } n=0; //定义定时器,500ms触发一次 QTimer *timer = new QTimer(this); timer->start(500); //信号与槽关联,定时器触发时响应Graph_Show()函数 connect(timer,SIGNAL(timeout()),this,SLOT(Graph_Show()));}Widget::~Widget(){ delete ui;}void Widget::Graph_Show(){ //取随机数,返回0-50之间的值 QTime t; t=QTime::currentTime(); qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); n=qrand()%50; //调用Graph_Show(QCustomPlot)函数 Graph_Show(ui->widget);}//画图void Widget::Graph_Show(QCustomPlot *CustomPlot){ //分别存储x坐标和y坐标 QVector<double> temp(10); QVector<double> temp1(10); for(int i=0; i<9; i++) { num[i]=num[i+1]; } num[9]=n; //初始化temp[]={0,1,2,3,4,5,6,7,8,9},temp1[]={0,0,0,0,0,0,0,0,0,0} for(int i=0;i<10;i++) { temp[i] = i; temp1[i] =num[i]; } //添加一条曲线 CustomPlot->addGraph(); //x是曲线序号,添加的第一条是0,设置曲线颜色 CustomPlot->graph(0)->setPen(QPen(Qt::red)); //输出各点的图像,x和y都是QVector类 CustomPlot->graph(0)->setData(temp,temp1); //x轴的文字 CustomPlot->xAxis->setLabel("t"); //y轴的文字 CustomPlot->yAxis->setLabel("mV"); //x轴范围 CustomPlot->xAxis->setRange(0,10); //y轴范围 CustomPlot->yAxis->setRange(-50,50); //重绘,这个是实时绘图的关键 CustomPlot->replot();}
原博主已经讲解的很清楚了,只是代码和解释没放在一起。
附上一张效果图:
阅读全文
0 0
- 用qt creator画实时图像
- 图像处理软件 Qt creator + opencv
- QT+QT creator+OpenCV图像灰度化
- Qt Creator
- Qt Creator
- qt creator
- qt creator
- qt creator
- qt creator
- qt creator 画点线,跟踪鼠标
- 【Qt】Qt Creator快捷键
- 用Qt creator编译QtAV库
- QT creator开发环境下界面更改后不能实时更新问题笔记
- 用 Qt Creator 开发非 Qt 的 C/C++ 程序
- 用Qt Creator实现Qt对话框上的菜单
- creator/QT入门 & QT Creator 使用
- MFC/QT 在控件上实时显示图像
- 安装 Qt Creator
- Unity入门操作_UGUI_Button理论_025
- python用open()函数打开.py等文档时出现编码错误解决办法
- Android项目汇总
- [主席树维护HASH && SET维护DFS序] Codechef. Walks on the binary tree
- Easyui Datagrid 根据字段动态合并行
- 用qt creator画实时图像
- js数组添加元素方式使用push
- strut2的进阶配置和属性参数设置获取问题
- py2exe的官方tutorial
- Socket,非阻塞,fcntl
- Log4j MDC使用案例
- Leetcode#53: Maximum Subarray
- jquery通过参数给select设置默认值
- Java类加载机制