基于串口收发数据的温度检测Qt界面程序

该博客介绍了一个使用Qt界面进行温度检测的程序,通过串口收发数据来展示温度变化曲线。虽然没有实际连接单片机,但能模拟显示室温数据的最大值和最小值。博客提供了相关源码文件,如view.h/cpp(绘制温度曲线),widget.h/cpp(主界面)以及RW.pro等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

基于串口收发的温度检测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 (new QGraphicsScene,parent),
      timeX(nullptr),
      tempY(nullptr),
      chart(nullptr)
{
    setDragMode(QGraphicsView::NoDrag);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

}
/*读取数据库数据并绘图*/
void View::getData(QString str){

    QSplineSeries *series=new QSplineSeries;
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值