Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to let .ini file's Non-Engilish text show normal?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    ljc123456gogo
    wrote on last edited by ljc123456gogo
    #1

    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.

    Keep Hungery, Keep Foolish!

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      L 1 Reply Last reply
      1
      • jsulmJ jsulm

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

        L Offline
        L Offline
        ljc123456gogo
        wrote on last edited by
        #3

        @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.

        Keep Hungery, Keep Foolish!

        1 Reply Last reply
        0
        • jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          L 1 Reply Last reply
          0
          • jsulmJ jsulm

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

            L Offline
            L Offline
            ljc123456gogo
            wrote on last edited by
            #5

            @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.

            Keep Hungery, Keep Foolish!

            1 Reply Last reply
            0
            • jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              L 1 Reply Last reply
              0
              • jsulmJ jsulm

                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?

                L Offline
                L Offline
                ljc123456gogo
                wrote on last edited by ljc123456gogo
                #7

                @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?

                Keep Hungery, Keep Foolish!

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved