PDA

View Full Version : Please help with codec in QSettings



lni
27th March 2014, 09:25
Hi,

I try to create an ini file using QSettings with utf8 codec, but I can' get key right regardless what I do. Please advise where I do wrong.

Thanks.



#include <QApplication>
#include <QSettings>
#include <QTextCodec>
#include <QDebug>

int main( int argc, char** argv )
{
QApplication app( argc, argv );

QTextCodec::setCodecForLocale( QTextCodec::codecForName( "utf8" ) );

QSettings settings( "Test.ini", QSettings::IniFormat );
settings.setIniCodec( QTextCodec::codecForName( "utf8" ) );

settings.beginGroup( "LITH_SEC" );

settings.setValue( QString::fromUtf8( "介壳灰岩" ), QString::fromUtf8( "灰岩" ) );
settings.setValue( QString::fromLocal8Bit( "介壳灰岩" ), QString::fromLocal8Bit( "灰岩" ) );
settings.setValue( "介壳灰岩", "灰岩" );
settings.setValue( QString( "介壳灰岩" ).toUtf8(), QString( "灰岩" ).toUtf8() );
settings.setValue( QString( "介壳灰岩" ).toLocal8Bit(), QString( "灰岩" ).toLocal8Bit() );

settings.endGroup();

}


It produces the following file:

[LITH_SEC]
%U4ECB%U58F3%U7070%U5CA9=灰岩
%E4%BB%8B%E5%A3%B3%E7%81%B0%E5%B2%A9=ç<81>°å²©
%C3%A4%C2%BB%C2%8B%C3%A5%C2%A3%C2%B3%C3%A7%C2%81%C 2%B0%C3%A5%C2%B2%C2%A9=@ByteArray(çÂ<81>°å²©)

wysota
27th March 2014, 09:34
What seems to be the problem? What did you expect to see in the output?

lni
27th March 2014, 10:58
I want to see the ini file to be:

[LITH)SEC]
介壳灰岩=灰岩

wysota
27th March 2014, 11:46
This ain't gonna happen, keys apparently need to have ASCII values only thus everything non-ASCII will be percentage encoded. If you really need that, you will have to provide your own backend for QSettings.