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 does not return strings containing commas correctly
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]QSettings does not return strings containing commas correctly

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 5.9k 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.
  • K Offline
    K Offline
    kenchan
    wrote on last edited by
    #1

    Hello,

    I am using the QSettings object to read an IniFormat file. I find that it will not return the correct string when commas are present. For example:
    When something like...
    @
    [SECTION]
    Value=1,2,4
    @

    is read, the result of doing
    @
    mySettings.value("Section/Value","").ToString();
    @

    would be "1". everything after the first comma is ignored.

    Can anyone please clarify if this is this the normal behaviour?

    I cannot find any mention of such behaviour in the documentation. Any suggestions as to to what one might do to work around this. Unfortunately I cannot change the contents of the INI file.

    Many thanks.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kenchan
      wrote on last edited by
      #2

      Actually, it would be more precise to say that this appears to be related to the fact that the string is not enclosed in quotes in the INI file.
      When there are Quotes around the string "1,2,3" it reads it fine otherwise it does not.
      Again, unfortunately I cannot change the way the strings are written in the INI file is written.

      I guess this is a candidate for writing my own read and write functions for this??

      Does anyone have any other suggestions?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        What type does the variant returned from QSettings::value() give you? I would not be surprised it is a list of some sort. That would enable doing something like:
        @
        mySettings.value("Section/Value").toStringList().join(",");
        @
        to get your string including the comma's back. Note that any white space in there would be lost though.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kenchan
          wrote on last edited by
          #4

          Thank you Andre,

          That was a very useful suggestion. Works like a charm.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            guru
            wrote on last edited by
            #5

            Im also having same issue, but in different place. I want to create a *.desktop file. in that file my group title was "Desktop Entry", after creating file and i saw in edit mode, group title was seems to like [Desktop Entry]. wats wrong with ma code.. this is my code...

            @ QSettings* settings = new QSettings(QDir::currentPath() + "/my_config_file.desktop", QSettings::IniFormat);
            settings->beginGroup("Desktop Entry"); // Title of group
            settings->setValue("Type", "Application");
            settings->setValue("Name","Autostart Script");
            settings->setValue("Exec","autostart");
            settings->setValue("Icon","system-run");
            settings->setValue("X-GNOME-Autostart-enabled","true");
            settings->setValue("Exec","/home/mysystem/app.sh &");
            settings->endGroup();
            settings->sync();@

            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