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 )
{
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();
}
#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();
}
To copy to clipboard, switch view to plain text mode
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 >°å²©)
Bookmarks