error read with useing QSettings

  • I use follow code to read ini file:

        QSettings settings(fileName, QSettings::IniFormat);
        settings.value("/Group/name", "default").toString();

    the value in the file without comma is right, but it goes error when it contains , and the strange is if comma is under Chinese input method not English it is right. How to solve this problem?

  • Lifetime Qt Champion

    @MLGDN Could you please explain better what the problem is?
    Can you show the ini file you're trying to read?
    And what error do you get?

  • @MLGDN Hi,friend. Welcome.

    I think you should not set utf-8. In Qt5 is not to set, just like below:

        QSettings settings("test.ini", QSettings::IniFormat);
        qDebug() << settings.value("key1","Default").toString();
        qDebug() << settings.value("key2","Default").toString();
        qDebug() << settings.value("key3","Default").toString();

    and the ini file:


    In the ini file, Qt used \x to encode Chinese.

  • @MLGDN
    When there is a comma in value of ini file and if you read the value with a key, it will return a list.
    settings.value("/Group/name", "default").toStringList(); will return an array of strings.
    for eg. if you have

    testKey=a,b,c,d in ini file and if you fetch value

    qDebug() << settings.value("testKey","default").toStringList();

    you will get
    ("a", "b", "c", "d")

  • @Tirupathi-Korla
    thank you , it works

  • @joeQ
    my file is utf-8 format, this way not works

Log in to reply