#include <QSettings>#include <QDebug>#include <QStringList>#include <QTextCodec>#include <QObject>int main(int argc, char **argv){ QTextCodec *codec = QTextCodec::codecForName("UTF-8"); QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QSettings set(app.applicationDirPath()+"/programs/cats.ini",QSettings::IniFormat); set.setIniCodec(codec); QString key = "секция/ключ"; QVariant value = "валуе"; set.setValue(key,value);}
QString key = QString::fromUtf8("секция/ключ");
#include <QtGui/QApplication>#include <QTextCodec>#include <QSettings>#include <QDebug>int main(int argc, char *argv[]){ QApplication a(argc, argv); QTextCodec *codec = QTextCodec::codecForName("Windows-1251"); QSettings ini(qApp->applicationDirPath()+"/programs/cats.ini",QSettings::IniFormat); ini.setIniCodec( codec ); ini.beginGroup(codec->toUnicode("группа")); ini.setValue(codec->toUnicode("ключ"),codec->toUnicode("валуя")); ini.endGroup(); return 0;}
void QSettings::setIniCodec ( const char * codecName )
QtJsonSettings::setIniCodec( "UTF-8" ); QString section_test = tr( "SECTION/TEST" ); QString section_1 = section_test + tr( "/NUMBER_1" ); QString section_2 = section_test + tr( "/NUMBER_2" ); QString value_rus = tr( "Значение" ); QString value_en = tr( "Value" ); QtJsonSettings::setValue( section_1, value_en ); QtJsonSettings::setValue( section_2, value_rus ); QtJsonSettings::sync();
QTextCodec* codec = QTextCodec::codecForName( "UTF-8" ); if ( codec != 0 ) { QTextCodec::setCodecForCStrings( codec ); QTextCodec::setCodecForLocale( codec ); QTextCodec::setCodecForTr( codec ); }