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. What is the correct way of doing setIniCodec("UTF-8") to a QSetting object?
Forum Update on Monday, May 27th 2025

What is the correct way of doing setIniCodec("UTF-8") to a QSetting object?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 2.6k 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.
  • T Offline
    T Offline
    thippu
    wrote on last edited by thippu
    #1

    Hi,
    I'm using windows and I would like to develop cross-platform .ini file reading and editing using Qt.
    My .ini file format is UTF-8. I did specify like this code:

    iniSettings=new QSettings(filename,QSettings::IniFormat,this);//allocationg the reference to QSettings
    iniSettings->setIniCodec("UTF-8");//I want in this format , if set also I'm getting out in ANSI.
    

    To ensure the QSetting is set to UTF-8 , I wrote all contents of the QSetting object to the another external file for testing purpose. checked it was ANSI and QSettings can't read backslashes and folder name with a number e.g:091-folder name
    So how to read and convert to the UTF-8 encoding format using QSettings?

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

      Hi,

      Can you provide an exact sample of code/data that shows that ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • 6thC6 Offline
        6thC6 Offline
        6thC
        wrote on last edited by
        #3
        QSettings settings(
          QSettings::IniFormat,
          QSettings::Scope::SystemScope,
          QCoreApplication::organizationName(),
          QCoreApplication::applicationName()
        );
        settings.setIniCodec("UTF-8");
        

        I do this. I can read anything (that's I've needed so far) from there.

        However, big red flag wave, making QSettings writes my ini file hashes and semicolons get trashed. Line comments stripped. Basically, it's a QSettings file with an ini extension, not an ini file.

        For reads it been fantastic - just beware if you are going to use QSettings for write ops... I just got bitten by this one too.

        1 Reply Last reply
        1
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @6thC said in What is the correct way of doing setIniCodec("UTF-8") to a QSetting object?:

          However, big red flag wave, making QSettings writes my ini file hashes and semicolons get trashed

          As long as QSettings can read it back in I don't see a reason why this should be a problem.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            You should read the note under the Format enum documenation which explains what happens with the .ini file format.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            2
            • T Offline
              T Offline
              thippu
              wrote on last edited by
              #6

              okay, now my requirement has been changed to reading ASCII encoding.

              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