Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-30068

QSettings can't work with INI files with BOM in the beginning

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 5.0.1
    • Core: Other
    • None
    • Win7, Qt 5.0.1

      When we have INI files like this:

      foo.ini

      <0xEF 0xBB 0xBF>[MainSection]
      MainKey1=11
      MainKey2=22
      
      [SecondSection]
      SecondSectionKey1=33
      SecondSectionKey2=44
      

      When we will try to work with this file in this way:

          QSettings  confFile(QLatin1String("d:/foo.ini"), QSettings::IniFormat);
          confFile.setIniCodec(QTextCodec::codecForName("UTF-8"));
      
          qDebug() << "groups" << confFile.childGroups();
      
      
          confFile.beginGroup(QLatin1String("SecondSection"));
          qDebug() << "keys (for secondary section)" << confFile.childKeys();
          confFile.endGroup();
      
          confFile.beginGroup(QLatin1String("MainSection"));
          qDebug() << "keys (for main section)" << confFile.childKeys();
          confFile.endGroup();
      

      we will got this output

      groups ("SecondSection")
      keys (for secondary section) ("SecondSectionKey1", "SecondSectionKey2")
      keys (for main section) ()

      But if we will remove BOM mark (in the beginning of file), we will get correct output:

      groups ("MainSection", "SecondSection")
      keys (for secondary section) ("SecondSectionKey1", "SecondSectionKey2")
      keys (for main section) ("MainKey1", "MainKey2")

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            peppe Giuseppe D'Angelo
            kittyhawk Bohdan
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes