To make sure I have the situation correct...
You have a UTF-8 encoded INI file that is being read by QSettings. When you retrieve the value of a key and try to interpret it as a QString you get the unexpected result from your first post.
This test program functions correctly if the codec is set before any access to the settings. If I access a setting, even a completely unrelated one, before setting the codec then the file is read and cached as Latin1 text.
#include <QtGui>
#include <QDebug>
int main(int argc, char *argv[])
{
// uncomment the following line to break it
// qDebug() << settings.value("missing").toString();
settings.setIniCodec("UTF-8");
qDebug() << settings.value("test").toString();
return app.exec();
}
#include <QtGui>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QSettings settings("test.ini", QSettings::IniFormat);
// uncomment the following line to break it
// qDebug() << settings.value("missing").toString();
settings.setIniCodec("UTF-8");
qDebug() << settings.value("test").toString();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
with
$ cat test.ini
test=°
$ od -tc -tx1 test.ini
0000000 t e s t = 302 260 \n
74 65 73 74 3d c2 b0 0a
$ cat test.ini
test=°
$ od -tc -tx1 test.ini
0000000 t e s t = 302 260 \n
74 65 73 74 3d c2 b0 0a
To copy to clipboard, switch view to plain text mode
outputs
"°"
"°"
To copy to clipboard, switch view to plain text mode
Bookmarks