Qt 无人机状态显示软件源码 持 Linux/Windows 平台,基于 Qt5.11 开发。
Qt无人机状态显示软件源码1.软件标题栏自定义2.机电状态信息包含当前时间、开车时间、飞行时间、电量指示器交、直、电池组成。3.机械信息包含燃油、燃油油温、刹车、滑油、滑油油温、液压、油门等信息组成。4.飞控信息包含地速、表速、真空速、气压、相对高度、GPS、无线电、航向指示器、精度、纬度信息组成以及指南针组成。源码代码都是经过验证可以直接编译运行2.Qt项目支持Linux和Windows平台运行3.调试时使用的Qt开发环境为Qt5.11一、项目结构UAVMonitor/ ├── UAVMonitor.pro # Qt项目文件 ├── main.cpp # 程序入口 ├── mainwindow.h/.cpp/.ui # 主窗口 ├── data_display.h/.cpp # 数据显示逻辑 └── images/ # 界面图标指南针等二、核心代码1.UAVMonitor.pro项目文件QT core gui widgets TARGET UAVMonitor TEMPLATE app SOURCES main.cpp \ mainwindow.cpp \ data_display.cpp HEADERS mainwindow.h \ data_display.h FORMS mainwindow.ui RESOURCES resources.qrc2.main.cpp程序入口#includeQApplication#includemainwindow.hintmain(intargc,char*argv[]){QApplicationa(argc,argv);MainWindow w;w.show();returna.exec();}3.data_display.h数据显示头文件#ifndefDATA_DISPLAY_H#defineDATA_DISPLAY_H#includeQObject#includeQTimer#includeQLabel#includeQProgressBarclassDataDisplay:publicQObject{Q_OBJECTpublic:explicitDataDisplay(QObject*parentnullptr);voidsetWidgets(QLabel*timeLabel,QLabel*driveTimeLabel,QLabel*flyTimeLabel,QProgressBar*fuelBar,QProgressBar*throttleBar,QLabel*groundSpeedLabel,QLabel*gpsLabel);privateslots:voidupdateData();private:QTimer*timer;QLabel*m_timeLabel;QLabel*m_driveTimeLabel;QLabel*m_flyTimeLabel;QProgressBar*m_fuelBar;QProgressBar*m_throttleBar;QLabel*m_groundSpeedLabel;QLabel*m_gpsLabel;};#endif// DATA_DISPLAY_H4.data_display.cpp数据更新逻辑#includedata_display.h#includeQDateTimeDataDisplay::DataDisplay(QObject*parent):QObject(parent){timernewQTimer(this);connect(timer,QTimer::timeout,this,DataDisplay::updateData);timer-start(1000);// 1秒刷新一次}voidDataDisplay::setWidgets(QLabel*timeLabel,QLabel*driveTimeLabel,QLabel*flyTimeLabel,QProgressBar*fuelBar,QProgressBar*throttleBar,QLabel*groundSpeedLabel,QLabel*gpsLabel){m_timeLabeltimeLabel;m_driveTimeLabeldriveTimeLabel;m_flyTimeLabelflyTimeLabel;m_fuelBarfuelBar;m_throttleBarthrottleBar;m_groundSpeedLabelgroundSpeedLabel;m_gpsLabelgpsLabel;}voidDataDisplay::updateData(){// 更新当前时间QString currentTimeQDateTime::currentDateTime().toString(yyyy-MM-dd HH:mm:ss);if(m_timeLabel)m_timeLabel-setText(currentTime);if(m_driveTimeLabel)m_driveTimeLabel-setText(currentTime);if(m_flyTimeLabel)m_flyTimeLabel-setText(currentTime);// 模拟燃油、油门、速度数据staticintfuel80;staticintthrottle50;staticintgroundSpeed1500;fuel-1;if(fuel20)fuel100;throttle5;if(throttle100)throttle0;groundSpeed10;if(groundSpeed1800)groundSpeed1400;if(m_fuelBar)m_fuelBar-setValue(fuel);if(m_throttleBar)m_throttleBar-setValue(throttle);if(m_groundSpeedLabel)m_groundSpeedLabel-setText(QString::number(groundSpeed));if(m_gpsLabel)m_gpsLabel-setText(2560);}5.mainwindow.h主窗口头文件#ifndefMAINWINDOW_H#defineMAINWINDOW_H#includeQMainWindow#includedata_display.hnamespaceUi{classMainWindow;}classMainWindow:publicQMainWindow{Q_OBJECTpublic:explicitMainWindow(QWidget*parentnullptr);~MainWindow();private:Ui::MainWindow*ui;DataDisplay*m_dataDisplay;};#endif// MAINWINDOW_H6.mainwindow.cpp主窗口实现#includemainwindow.h#includeui_mainwindow.hMainWindow::MainWindow(QWidget*parent):QMainWindow(parent),ui(newUi::MainWindow){ui-setupUi(this);setWindowTitle(无人机状态显示);// 自定义标题栏// 初始化数据显示模块m_dataDisplaynewDataDisplay(this);m_dataDisplay-setWidgets(ui-label_time,ui-label_drive_time,ui-label_fly_time,ui-progressBar_fuel,ui-progressBar_throttle,ui-label_ground_speed,ui-label_gps);}MainWindow::~MainWindow(){deleteui;}三、mainwindow.ui界面设计说明与截图匹配你可以在 Qt Designer 中按如下方式设计界面区域控件作用左侧上方QLabel×3显示当前时间、开车时间、飞行时间左侧下方QProgressBar×4燃油、滑油、刹车、液压状态条中间QLabel自定义绘制姿态指示器地平仪右侧上方QLabel×8地速、表速、真空速、气压、相对高度、GPS、经度、纬度右侧下方QWidget自定义绘制指南针航向指示器四、编译运行说明环境要求Qt 5.11或更高版本支持 Windows / Linux。编译步骤新建 Qt Widgets Application 项目将上述代码复制到对应文件在 Qt Designer 中按说明设计mainwindow.ui构建并运行项目。扩展功能如需真实数据接入修改data_display.cpp中的updateData()函数从串口/网络读取数据如需自定义地平仪、指南针可使用QWidget重写paintEvent绘制。