气候控制小部件示例
此示例展示如何从C++访问气候控制。
此示例展示如何从C++访问气候控制。
首先需要做的是在MainWindow构造函数中创建一个QIviClimateControl实例。因为我们只有一个气候后端,并且不想选择使用哪一个,所以我们直接调用startAutoDiscovery立即开始搜索合适的后端,并选择第一个匹配的后端。
注意:为了简化部署过程,此示例加载了模拟后端。
isValid()用于验证autoDiscovery是否找到一个后端
m_climateControl = new QIviClimateControl(QString(), this); m_climateControl->setDiscoveryMode(QIviAbstractFeature::LoadOnlySimulationBackends); m_climateControl->startAutoDiscovery(); if (!m_climateControl->isValid()) QMessageBox::critical(this, tr("Auto Discovery Failed !"), tr("No Climate Backend available"));
构造函数接着将气候控制的属性变化信号连接到UI组件
//Air Flow Direction setupFlowDirectionRadioButtons(m_climateControl->airflowDirections()); connect(m_buttonGroup, static_cast<void (QButtonGroup::*)(QAbstractButton *, bool)>(&QButtonGroup::buttonToggled), this, &MainWindow::onFlowDirectionButtonToggled); connect(m_climateControl, &QIviClimateControl::airflowDirectionsChanged, this, &MainWindow::setupFlowDirectionRadioButtons); //Air Condition ui->cb_airCondition->setChecked(m_climateControl->isAirConditioningEnabled()); connect(m_climateControl, &QIviClimateControl::airConditioningEnabledChanged, ui->cb_airCondition, &QCheckBox::setChecked); connect(ui->cb_airCondition, &QCheckBox::clicked, m_climateControl, &QIviClimateControl::setAirConditioningEnabled); //Air Recirculation ui->cb_airRecirculation->setChecked(m_climateControl->recirculationMode() == QtIviVehicleFunctionsModule::RecirculationOn); connect(m_climateControl, &QIviClimateControl::recirculationModeChanged, this, &MainWindow::onAirRecirculationModeChanged); connect(ui->cb_airRecirculation, &QCheckBox::clicked, this, &MainWindow::setAirRecirculationEnabled); //Heater ui->cb_heater->setChecked(m_climateControl->isHeaterEnabled()); connect(m_climateControl, &QIviClimateControl::heaterEnabledChanged, ui->cb_heater, &QCheckBox::setChecked); connect(ui->cb_heater, &QCheckBox::clicked, m_climateControl, &QIviClimateControl::setHeaterEnabled); }
使用这些函数可以控制气流方向
void MainWindow::setupFlowDirectionRadioButtons(QtIviVehicleFunctionsModule::AirflowDirections direction) { ui->cb_windshield->setChecked(direction.testFlag(QtIviVehicleFunctionsModule::Windshield)); ui->cb_dashboard->setChecked(direction.testFlag(QtIviVehicleFunctionsModule::Dashboard)); ui->cb_floor->setChecked(direction.testFlag(QtIviVehicleFunctionsModule::Floor)); } void MainWindow::onFlowDirectionButtonToggled(QAbstractButton *button, bool checked) { Q_UNUSED(button) Q_UNUSED(checked) QtIviVehicleFunctionsModule::AirflowDirections direction; if (ui->cb_windshield->isChecked()) direction |= QtIviVehicleFunctionsModule::Windshield; if (ui->cb_dashboard->isChecked()) direction |= QtIviVehicleFunctionsModule::Dashboard; if (ui->cb_floor->isChecked()) direction |= QtIviVehicleFunctionsModule::Floor; m_climateControl->setAirflowDirections(direction); }
©2020 Qt公司。本文档中的文档贡献的版权属于各自的所有者。提供的文档在自由软件基金会的GNU自由文档许可1.3版的条款下许可发布。Qt及其相关标志为芬兰和/或其他国家的Qt公司的商标。所有其他商标均为各自所有者的财产。