基于串口收发的温度检测qt界面
温度变化曲线
温度数据显示
实时温度,由于这里并没有用串口连接单片机,所以没有数据显示
室温数据分析则是找出温度最大值最小值显示出来
温差变化曲线和更新进度功能没有具体地功能的实现
RW.pro文件
QT += serialport
QT += sql
QT += charts
connect.h文件(连接数据库)
#ifndef CONNECT_H
#define CONNECT_H
#include<QtSql/QSqlDatabase>
#include<QtSql/QSqlQuery>
#include<QtSql/QSqlRecord>
#include<QtDebug>
static bool connectSQL(){
QSqlDatabase tempData=QSqlDatabase::addDatabase("QMYSQL");
tempData.setHostName("localhost");
tempData.setDatabaseName("receivetemp");
tempData.setUserName("root");
tempData.setPort(3306);
tempData.setPassword("123456");
if(!tempData.open()){
return false;
}
return true;
}
#endif // CONNECT_H
view.h和view.cpp文件(温度变化曲线表格的绘制)
view.h
#ifndef VIEW_H
#define VIEW_H
#include<QtWidgets/QGraphicsView>
#include<QtCharts/QChartGlobal>
#include<QtCharts/QChartView>
QT_BEGIN_NAMESPACE
class QMouseEvent;
class QResizeEvent;
class QGraphicsScene;
QT_END_NAMESPACE
QT_CHARTS_BEGIN_NAMESPACE
class QChart;
QT_CHARTS_END_NAMESPACE
QT_CHARTS_USE_NAMESPACE
class View : public QGraphicsView
{
public:
View(QWidget *parent=nullptr);
void getData(QString str);
protected:
void resizeEvent(QResizeEvent *event);
void mouseMoveEvent(QMouseEvent *event);
private:
QGraphicsSimpleTextItem *timeX;
QGraphicsSimpleTextItem *tempY;
QChart *chart;
QChartView *chartView;
};
#endif // VIEW_H
view.cpp
#include "view.h"
#include"connect.h"
#include<QtGui/QResizeEvent>
#include<QtGui/QMouseEvent>
#include<QtWidgets/QGraphicsScene>
#include<QtWidgets/QGraphicsSimpleTextItem>
#include<QtCharts/QSplineSeries>
#include<QtCharts/QDateTimeAxis>
#include<QtCharts/QValueAxis>
#include<QtCharts/QChart>
#include<QtCharts/QChartView>
#include<QDateTime>
View::View(QWidget *parent)
:QGraphicsView (ne