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
...
[Patient_Info]
HeightIsVisible=True
HeightIsMandatory=True
WeightIsVisible=True
WeightIsMandatory=True
...
To copy to clipboard, switch view to plain text mode
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)
Q_PROPERTY( QVariantMap patientInfoAttributes READ getPatientInfoAttributes NOTIFY patientInfoAttributesChanged)
To copy to clipboard, switch view to plain text mode
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"]
property bool heightIsVisible : Helper.patientInfoAttributes["HeightIsVisible"]
property bool heightIsMandatory : Helper.patientInfoAttributes["HeightIsMandatory"]
property bool weightIsVisible : Helper.patientInfoAttributes["WeightIsVisible"]
property bool weightIsMandatory : Helper.patientInfoAttributes["WeightIsMandatory"]
To copy to clipboard, switch view to plain text mode
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"]
property var backupSelector : Helper.sessionAttributes["SelectorIsVisible"]
To copy to clipboard, switch view to plain text mode
An alternate declaration which also works:
property bool backupSelector : (Helper.sessionAttributes["SelectorIsVisible"] === "true")
property bool backupSelector : (Helper.sessionAttributes["SelectorIsVisible"] === "true")
To copy to clipboard, switch view to plain text mode
The following assignment always returns true regardless of the property value read using QSettings
property var backupSelector : Helper.sessionAttributes["SelectorIsVisible"]
property var backupSelector : Helper.sessionAttributes["SelectorIsVisible"]
To copy to clipboard, switch view to plain text mode
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
Bookmarks