PDA

View Full Version : QML and QSettings



DLabonte
15th June 2018, 15:52
Good morning,

I have a question related to the use of QSettings and using a value in a QML dialog. I have tried different approaches where an application setting is assigned a boolean (True/False) as shown here:

[Patient_Info]
HeightIsVisible=True
HeightIsMandatory=True
WeightIsVisible=True
WeightIsMandatory=True
...


The configuration file is read in a C++ method, key and values saved in a QVariantMap variable which is defined as Q_PROPERTY


Q_PROPERTY( QVariantMap patientInfoAttributes READ getPatientInfoAttributes NOTIFY patientInfoAttributesChanged)


The variable patientInfoAttributes is accessed in the QML code as shown below, and different path of execution are executed depending on the values. In the QML code, the values are correctly treated as boolean.


property bool heightIsVisible : Helper.patientInfoAttributes["HeightIsVisible"]
property bool heightIsMandatory : Helper.patientInfoAttributes["HeightIsMandatory"]
property bool weightIsVisible : Helper.patientInfoAttributes["WeightIsVisible"]
property bool weightIsMandatory : Helper.patientInfoAttributes["WeightIsMandatory"]


There is another instance, in another QML file, where a similar approach is taken, but without success. Rather than simply setting a boolean property as above, the working is shown here:


property var backupSelector : Helper.sessionAttributes["SelectorIsVisible"]

An alternate declaration which also works:


property bool backupSelector : (Helper.sessionAttributes["SelectorIsVisible"] === "true")


The following assignment always returns true regardless of the property value read using QSettings


property var backupSelector : Helper.sessionAttributes["SelectorIsVisible"]


I am at a lost to understand the difference in behaviour. Any suggestions?
I am using Qt5.5.1 running on a Windows 10.

Regards,
Daniel