Let's say I have a simple QMap declared and initialized with values inside C++ and properly exposed to QML.
C++
QMap<QString, QMap<QString, QString>> airflow_buttons_;
//simple getter
[[nodiscard]] QMap<QString, QMap<QString, QString>> airflow_buttons() const;
QML
console.log(ClimateModel.airflow_buttons);
the output displayed is:
(qrc:/Climate/AirflowButtons.qml:24) - QVariant(QMap<QString,QMap<QString,QString>>, QMap(("left", QMap(("top_air", "NOT_ACTIVE")))))
The output is in the form of a QVariant. I am unsure how to convert it to a Map with the desired values.
I aim to utilize it as a straightforward JavaScript Map.
console.log(ClimateModel.airflow_buttons["left"]["top_air"]); //Should display "NOT_ACTIVE"
console.log(ClimateModel.airflow_buttons["left"]); //Should show the Map contents
The current error message indicates
[debug] expression for onCompleted (qrc:/Climate/AirflowButtons.qml:24) - undefined
To illustrate what I intend to achieve in plain JavaScript:
var myMap = {x: "Test", y: "Test 2"};
myMap["z"] = "Test 3";
console.log(myMap["z"]); //displays "Test 3"
console.log(JSON.stringify(myMap["z"])); //displays the map contents
How can I accomplish this seemingly simple task?