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. [SOLVED] QSettings Codec Problem
QtWS25 Last Chance

[SOLVED] QSettings Codec Problem

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 7.7k Views
  • 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.
  • Y Offline
    Y Offline
    yaseminyilmaz
    wrote on last edited by
    #1

    Hi all,

    I try to read the values from an ini file using by QSettings. That file includes Turkish characters (İ, ç, ğ, etc). I can't solve this problem although I've used setIniCodec. What can the problem be?

    @ QSettings mSettings("params.ini", QSettings::IniFormat);
    mSettings.setIniCodec("ISO 8859-9");
    QStringList mAliases = mSettings.value("SerialNumbers/AliasList").toString().split(",");
    @

    The content of Ini file:
    [SerialNumbers]
    AliasList="TSD,YBS,İAS"

    The values of mAliases: TSD, YBS, \460AS

    Thanks a lot for your helps and clarification.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Galactik
      wrote on last edited by
      #2

      I'm not sure of that but i believe the ini file stores the string as UTF8, so you might want to try replace toString() with a toByteArray(), and then use QString::fromUtf8() to construct your string.

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        yaseminyilmaz
        wrote on last edited by
        #3

        Thanks Galactik. I've tried your advice as the following below. The result string has been "TSD, YBS, ?AS".

        I've noticed that ini file encoded by ANSI using by notepad++. I've converted to UTF-8 but the result string is empty after the encoding modification. How can I solve this problem?

        @
        QSettings mSettings("params.ini", QSettings::IniFormat);
        mSettings.setIniCodec("ISO 8859-9");
        QByteArray mList = mSettings.value("SerialNumbers/AliasList").toByteArray();
        QString string = QString::fromUtf8(mList);
        @

        Thanks advance for your helps

        1 Reply Last reply
        1
        • G Offline
          G Offline
          Galactik
          wrote on last edited by
          #4

          After saving the ini file as a UTF-8 file, you should then modify your setIniCodec to setIniCodec("UTF-8");

          1 Reply Last reply
          1
          • Y Offline
            Y Offline
            yaseminyilmaz
            wrote on last edited by
            #5

            Thanks Galactik.

            The problem has been solved by using QTextCodec::setCodecForCStrings.

            1 Reply Last reply
            1
            • S Offline
              S Offline
              songzhao831
              wrote on last edited by
              #6

              I meet the similar issue, but i have chinese in ini file.
              QT5 already remove QTextCodec::setCodecForCStrings.
              Do you have some resolution?

              1 Reply Last reply
              0
              • T Offline
                T Offline
                texpert
                wrote on last edited by
                #7

                QSettings::setIniCodec

                The codec must be set immediately after creating the QSettings object, before accessing any data.

                Sincerely yours, amigos!

                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