Climate Control Widget Example
This example shows how to access the climate control from C++.
This example shows how to access the climate control from the C++.
The first thing to do is to create a QIfClimateControl instance in our MainWindow constructor. As we only have one Climate backend and don't want to choose which one to use, we call startAutoDiscovery to start searching for a suitable backend right away and pick the first one that matches.
Note: To simplify the deployment process, this example loads a simulation backend.
isValid() is used for verifying that the autoDiscovery found a backend:
m_climateControl = new QIfClimateControl(QString(), this); m_climateControl->setDiscoveryMode(QIfAbstractFeature::LoadOnlySimulationBackends); m_climateControl->startAutoDiscovery(); if (!m_climateControl->isValid()) QMessageBox::critical(this, tr("Auto Discovery Failed !"), tr("No Climate Backend available"));
The constructor then continues to connect the climate control attribute change signals to the UI components:
//Air Flow Direction setupFlowDirectionRadioButtons(m_climateControl->airflowDirections()); connect(m_buttonGroup, static_cast<void (QButtonGroup::*)(QAbstractButton *, bool)>(&QButtonGroup::buttonToggled), this, &MainWindow::onFlowDirectionButtonToggled); connect(m_climateControl, &QIfClimateControl::airflowDirectionsChanged, this, &MainWindow::setupFlowDirectionRadioButtons); //Air Condition ui->cb_airCondition->setChecked(m_climateControl->isAirConditioningEnabled()); connect(m_climateControl, &QIfClimateControl::airConditioningEnabledChanged, ui->cb_airCondition, &QCheckBox::setChecked); connect(ui->cb_airCondition, &QCheckBox::clicked, m_climateControl, &QIfClimateControl::setAirConditioningEnabled); //Air Recirculation ui->cb_airRecirculation->setChecked(m_climateControl->recirculationMode() == QtIfVehicleFunctions::RecirculationOn); connect(m_climateControl, &QIfClimateControl::recirculationModeChanged, this, &MainWindow::onAirRecirculationModeChanged); connect(ui->cb_airRecirculation, &QCheckBox::clicked, this, &MainWindow::setAirRecirculationEnabled); //Heater ui->cb_heater->setChecked(m_climateControl->isHeaterEnabled()); connect(m_climateControl, &QIfClimateControl::heaterEnabledChanged, ui->cb_heater, &QCheckBox::setChecked); connect(ui->cb_heater, &QCheckBox::clicked, m_climateControl, &QIfClimateControl::setHeaterEnabled); }
Airflow direction is controlled using these functions:
void MainWindow::setupFlowDirectionRadioButtons(QtIfVehicleFunctions::AirflowDirections direction) { ui->cb_windshield->setChecked(direction.testFlag(QtIfVehicleFunctions::Windshield)); ui->cb_dashboard->setChecked(direction.testFlag(QtIfVehicleFunctions::Dashboard)); ui->cb_floor->setChecked(direction.testFlag(QtIfVehicleFunctions::Floor)); } void MainWindow::onFlowDirectionButtonToggled(QAbstractButton *button, bool checked) { Q_UNUSED(button) Q_UNUSED(checked) QtIfVehicleFunctions::AirflowDirections direction; if (ui->cb_windshield->isChecked()) direction |= QtIfVehicleFunctions::Windshield; if (ui->cb_dashboard->isChecked()) direction |= QtIfVehicleFunctions::Dashboard; if (ui->cb_floor->isChecked()) direction |= QtIfVehicleFunctions::Floor; m_climateControl->setAirflowDirections(direction); }
© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.