How to let .ini file's Non-Engilish text show normal?



  • HI!
    I want the .ini use non-english text:

    m_ConfigIni = new QSettings(QString::fromLocal8Bit("./Resources/自定义配置.ini"),QSettings::IniFormat);
    m_ConfigIni->setIniCodec("UTF-8");
    m_ConfigIni->setValue(QString::fromLocal8Bit("/首界面/测试"),QString::fromLocal8Bit("结果"));
    

    but it can't show normal like:

    [%U9996%U754C%U9762]
    %U6D4B%U8BD5=结果

    The filename and value is normal, but the key show messy. I use setinicodec with utf-8, but not work. How to fix it ?
    Thanks in advance.


  • Moderators

    Why QString::fromLocal8Bit? It expects 8bit string as input but you're using unicode! Why not just use QString?



  • @jsulm
    Because use fromLocal8Bit () function has realized the transform from the local character set GB to the Unicode , mainly used in processing Chinese display messy.
    If change to use Qstring directly, it even become worse than before, because the filename, key and value all show messy.


  • Moderators

    Did you try something else? QString::fromLocal8Bit("/首界面/测试"): 首界面/测试 is not a 8bit string and it's not GB.
    Try fromUtf8().



  • @jsulm

    Is it you mean that ? :

    	QSettings *m_ConfigIni = new QSettings(QString::fromUtf8("./Resources/自定义配置.ini"),QSettings::IniFormat);
    	m_ConfigIni->setIniCodec("UTF-8");
    	m_ConfigIni->setValue(QString::fromUtf8("/首界面/测试"),QString::fromUtf8("结果"));
    

    But not help. Filename, key and value all show messy. Did I do something wrong?

    Thanks for your enthusiastic help.


  • Moderators

    Are you sure it is stored wrongly? Maybe it is your editor showing it this way? What happens if you try to read the key-value?



  • @jsulm

    I just want the users double click the .ini file with Win7's notepad to edit it, but in the notepad it show messy now:

    [%UFFFD%U05FD%UFFFD%UFFFD%UFFFD]
    %UFFFD%UFFFD%UFFFD%UFFFD=����

    read it also abnormal. I try:

    qDebug() << m_ConfigIni->value(QString::fromUtf8("/首界面/测试")).toString();
    

    qDebug print:

    "????"

    before I use fromLocal8Bit even can read the result normal. Is there any other way?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.