How to read a value using QSetting if the value contains comma character [duplicate]

半腔热情 提交于 2020-01-01 21:57:47

问题


In my QT project I am reading values from .ini file using QSettings. If the value contains comma character QSettings is not able to read it. How should I read such values?


回答1:


Comma character is treated as list separator by QSettings. INI values with commas are parsed as string lists. You can convert a string list back to original string as follows:

QVariant value = settings.value("key");
QString string;
if (value.type() == QVariant::StringList) {
  string = value.toStringList().join(",");    
} else {
  string = value.toString();
}



回答2:


simply create a ini file with qsettings and a comma in configuration string. Characters being control chars for ini-files will be escaped by % percent sign.



来源:https://stackoverflow.com/questions/18052930/how-to-read-a-value-using-qsetting-if-the-value-contains-comma-character

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!