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

StackOverflow https://stackoverflow.com/questions/18052930

  •  23-06-2022
  •  | 
  •  

Pregunta

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?

¿Fue útil?

Solución

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();
}

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top