C
Qt Quick Ultralite 汽车仪表盘演示
演示了 QML 与 C++ 的集成,以及第三方库的使用。
概述
这是一个复杂的应用程序,展示了使用Qt Quick Ultralite构建的应用程序的许多方面:
- 将 C++ 业务逻辑与 QML 应用程序集成
- 通过拆分为多个QML组件来处理复杂的用户界面
- 在不牺牲性能的前提下,使用复杂的动画效果以提供最佳用户体验
屏幕中央区域可在四个不同的页面之间切换:
- 媒体播放器
- 电话
- 逐向导航
- 设置
可以通过键盘输入来控制页面和菜单,使用的是台式计算机上的键盘。此外,还可以通过Renesas Mango主板上的实体HMI旋钮和四向方向键进行控制:
| 操作 | 桌面 | RH850-D1M1A |
|---|---|---|
| 向上导航 | 向上键 | 向上切换 |
| 向下导航 | 向下键 | 向下切换 |
| 向左导航 | 左键 | 向左切换 |
| 向右导航 | 右键 | 向右切换 |
| 向右导航 | 空格键 | 切换中心按键 |
| 下一页 | 向上键 | 旋钮向右 |
| 上一页 | 向下键 | 旋钮向左 |
| 确认 | 回车键 | 按下旋钮 |
使用仿真控制器控制演示
还可以通过automotive/src/simulationcontroller.h 中的 C 语言链接 API 来控制该演示程序。
每个键都有一个以qul_application_control_ 为前缀的对应 API 函数。调用该函数时,将pressed 设为true ,然后将pressed 设为false ,即可触发应用程序的按键操作。
要禁用页面、菜单和模式的自动切换,请调用qul_application_force_interactive_mode ,并将force_interactive_mode 作为true 传入。
要禁用模拟驱动器数据,请调用一次qul_application_show_simulated_drive_data ,并将simulated_drive_data 作为false 传入。之后,调用设置函数(例如qul_application_set_speed )来设置速度值。
要禁用车道辅助动画,请调用qul_application_set_lane_assistant_enabled ,并将enabled 作为false 传入。
要禁用模拟转向灯,请调用一次qul_application_show_simulated_light_indicators ,并将simulated_light_indicators 作为false 传入。之后,调用设置函数,例如qul_application_set_left_blinker_on ,并将left_blinker_on 作为true 传入,以开启左转向灯。
文件变体
该汽车演示通过文件变体和选择器,将应用程序定制为适用于不同的演示区域。
如果未应用任何选择器,演示区域将默认设置为德国,使用公制单位以及德语街道名称和交通标志。您可以通过文件变体构建演示,以显示英制单位和/或美国本地化的街道名称及限速标志。应用"imperial" 文件选择器以使用英制单位,应用"usa" 选择器以使用美国本地化的街道名称和交通标志。
qmlprojectexporter demos/automotive/qmlproject/automotive.qmlproject --outdir=<output_dir> --selector=imperial,usa
使用 CMake 构建演示程序时,将DEMO_REGION 变量设置为"usa" ,还会添加"imperial" 选择器,以便为美国用户简化应用程序的构建:
cmake -DDEMO_REGION="usa" <additional args>
目标平台
屏幕截图
正常模式

运动模式

基准测试模式
在基准测试模式下,应用程序将运行预设的30秒时间,并在30秒间隔结束时在屏幕上显示性能指标。如果Qt Quick Ultralite Core库是使用QUL_ENABLE_PERFORMANCE_CONSOLE_OUTPUT=ON 编译的,则相同的结果也会显示在串行控制台上。
测试结束时将显示以下性能指标:
| 参数 | 描述 | |
|---|---|---|
| 1 | 总帧数 | 录制区间内的帧总数。 |
| 2 | 平均帧率 | 在录制时间段内测得的平均每秒帧数。 |
| 3 | 最低帧率 | 录制期间捕获的最低帧率值。 |
| 4 | 最大堆内存使用量 | 自应用程序启动以来记录的最大堆内存使用量(单位:字节)。 |
| 5 | 最大栈使用量 | 自应用程序启动以来记录的栈最大使用量(以字节为单位)。 |
| 6 | 平均 CPU 负载 | 记录时间段内 CPU 负载的平均百分比值。 |
基准测试模式作为独立的 CMake 目标提供,名称为automotive_benchmark 。要运行基准测试模式,请构建并烧录目标automotive_benchmark 。
automotive_benchmark 目标需要添加编译定义QUL_DEMO_BENCHMARK_MODE 。
target_compile_definitions(automotive_benchmark PRIVATE
QUL_DEMO_BENCHMARK_MODE
)automotive.qmlproject 文件包含benchmark_module.qmlproject 文件,如下所示:
ModuleFiles {
files: [
"benchmark/benchmark_module.qmlproject"
]
}在根 QML 文件中导入以下模块。
import QtQuickUltralite.Extras 2.0 import Benchmark 1.0 import QtQuickUltralite.Profiling
- Qt Quick Ultralite Extras 该模块提供了QulPerf 对象,可用于启动和停止测量。
Benchmark该模块由benchmark_module.qmlproject文件提供。它提供了用于模拟触控手势以实现轻扫控制的方法。- Qt Quick Ultralite Profiling 该模块提供了屏幕叠加层QulPerfOverlay ,用于在应用程序用户界面上方显示性能指标。
在根 qml 中添加用于显示基准测试结果的QulPerfOverlay QML 对象。当 30 秒后触发benchmarkTimer 时,该叠加层将显示出来。
QulPerfOverlay {
id: benchmarkResult
anchors.horizontalCenter: parent.horizontalCenter;
anchors.verticalCenter: parent.verticalCenter;
visible: false
}当根对象被实例化且触发Component.onCompleted 信号时,在根QML项中开始录制。
Component.onCompleted: {
QulPerf.recording = true
}应用程序运行 30 秒。30 秒后停止录制,并显示基准测试结果的屏幕叠加层。
Timer {
id: benchmarkTimer
interval: 30000
running: true
repeat: false
onTriggered: {
QulPerf.recording = false;
benchmarkResult.visible = true
}
}注意:基准测试模式 要求Qt Quick 的Ultralite Core和Platform库必须使用QUL_ENABLE_PERFORMANCE_LOGGING=ON 和QUL_ENABLE_HARDWARE_PERFORMANCE_LOGGING=ON 进行构建。
文件:
- automotive/+imperial/SpeedLimitImage.qml
- automotive/+imperial/SpeedLimitValues.qml
- automotive/+imperial/Units.qml
- automotive/+ra8d1/automotive.qml
- automotive/BaseGauge.qml
- automotive/CMakeLists.txt
- automotive/CarStatus.qml
- automotive/DriveModeSelector.qml
- automotive/Gauge.qml
- automotive/GuideArrow.qml
- automotive/GuideArrowItem.qml
- automotive/LaneAssist.qml
- automotive/LaneAssistWhiteLine.qml
- automotive/LinearGauge.qml
- automotive/MediaPlayer.qml
- automotive/Menu.qml
- automotive/MiddleGauge.qml
- automotive/Navi.qml
- automotive/NormalMode.qml
- automotive/NormalModeContentItem.qml
- automotive/Phone.qml
- automotive/SpeedLimitImage.qml
- automotive/SpeedLimitValues.qml
- automotive/SpeedWarningIndicator.qml
- automotive/SportGauge.qml
- automotive/SportMode.qml
- automotive/TellTales.qml
- automotive/TellTalesIndicator.qml
- automotive/TempGauge.qml
- automotive/Units.qml
- automotive/automotive.qml
- automotive/benchmark/benchmark_module.qmlproject
- automotive/benchmark/benchmarkmode.h
- automotive/imports/Automotive/MainModel.qml
- automotive/imports/Automotive/MathAPI.qml
- automotive/imports/Automotive/MediaPlayerModel.qml
- automotive/imports/Automotive/NaviModel.qml
- automotive/imports/Automotive/NormalModeModel.qml
- automotive/imports/Automotive/PhoneModel.qml
- automotive/imports/Automotive/SettingsMenuModel.qml
- automotive/imports/Automotive/SportModeModel.qml
- automotive/imports/Automotive/Style.qml
- automotive/imports/Automotive/TellTalesModel.qml
- automotive/imports/Automotive/qmldir
- automotive/qmlproject/automotive.qmlproject
- automotive/qmlproject/automotive_module.qmlproject
- automotive/qmlproject/automotive_ra8d1.qmlproject
- automotive/qmlproject/automotive_traveo_t2g.qmlproject
- automotive/region/+usa/Region.qml
- automotive/region/Region.qml
- automotive/src/connectivityservice.cpp
- automotive/src/connectivityservice.h
- automotive/src/hmi_input/CMakeLists.txt
- automotive/src/hmi_input/hmi_input.cpp
- automotive/src/hmi_input/hmi_input.h
- automotive/src/hmi_input/hmi_input_event.h
- automotive/src/hmi_input/rh850-d1m1a-baremetal/CMakeLists.txt
- automotive/src/hmi_input/rh850-d1m1a-baremetal/rh850.cpp
- automotive/src/mathutils.h
- automotive/src/platform/baremetal/main.cpp
- automotive/src/simulation/drivestates.cpp
- automotive/src/simulation/drivestates.h
- automotive/src/simulation/drivetrain.cpp
- automotive/src/simulation/drivetrain.h
- automotive/src/simulation/lights.cpp
- automotive/src/simulation/lights.h
- automotive/src/simulation/smfwd.h
- automotive/src/simulation/speedlimits.cpp
- automotive/src/simulation/speedlimits.h
- automotive/src/simulation/stateid.h
- automotive/src/simulation/states.cpp
- automotive/src/simulation/states.h
- automotive/src/simulationcontroller.cpp
- automotive/src/simulationcontroller.h
- automotive/src/statemachine.h
图片:
- automotive/images/airbag.png
- automotive/images/albums/ak.png
- automotive/images/albums/juno.png
- automotive/images/albums/phazz.png
- automotive/images/albums/thievery-corp.png
- automotive/images/albums/tycho.png
- automotive/images/arrow-0.png
- automotive/images/arrow-45.png
- automotive/images/arrow-90.png
- automotive/images/arrow-round.png
- automotive/images/assets-phone-list-pseudo-mask.png
- automotive/images/battery.png
- automotive/images/bg-mask.png
- automotive/images/car-highlights.png
- automotive/images/clock.png
- automotive/images/fuel.png
- automotive/images/gauge-gauge-frame-sport-center.png
- automotive/images/gauge-gauge-frame-sport-side.png
- automotive/images/gauge-gauge-frame.png
- automotive/images/gauge-normal.png
- automotive/images/highlight-big-sport.png
- automotive/images/highlight-normal.png
- automotive/images/highlight-standard-sport.png
- automotive/images/leaf.png
- automotive/images/low-beam-headlights.png
- automotive/images/navi.png
- automotive/images/needle-normal.png
- automotive/images/needle-standard-sport.png
- automotive/images/oil-temp.png
- automotive/images/parked.png
- automotive/images/parking-lights.png
- automotive/images/phone.png
- automotive/images/photos/aryn.png
- automotive/images/photos/beatriz.png
- automotive/images/photos/caspar.png
- automotive/images/photos/hirini.png
- automotive/images/photos/joslin.png
- automotive/images/play.png
- automotive/images/pseudo-mask-vertical.png
- automotive/images/ready.png
- automotive/images/red-border-left.png
- automotive/images/red-border-right.png
- automotive/images/road.png
- automotive/images/setup.png
- automotive/images/speed-limit-warning.png
- automotive/images/speed-limit-warnings/140.png
- automotive/images/speed-limit-warnings/20mph.png
- automotive/images/speed-limit-warnings/30.png
- automotive/images/speed-limit-warnings/35mph.png
- automotive/images/speed-limit-warnings/45mph.png
- automotive/images/speed-limit-warnings/50.png
- automotive/images/speed-limit-warnings/55mph.png
- automotive/images/speed-limit-warnings/70.png
- automotive/images/speed-limit-warnings/85mph.png
- automotive/images/speed-limit-warnings/90.png
- automotive/images/sport.png
- automotive/images/top-line.png
- automotive/images/turn_left.png
- automotive/images/turn_right.png
- automotive/images/white-line-left.png
- automotive/images/white-line-right.png
在某些 Qt 许可下可用。
了解更多信息。