2

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?

2
  • 1
    Comma character is treated as list separator by QSettings. Try to use qDebug() << settings.value("key"); to see what it loads from your file. If it is a string list, you can convert it to string using join(","). Commented Aug 5, 2013 at 8:27
  • @PavelStrakhov Yes, it is loading as QStringList. Commented Aug 5, 2013 at 8:38

2 Answers 2

7

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(); } 
Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

I think OP is talking about INI files not generated by Qt.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.