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. QSettings - get setting value of form x,x|x,x|x,x|x,x| fails
Forum Updated to NodeBB v4.3 + New Features

QSettings - get setting value of form x,x|x,x|x,x|x,x| fails

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 2.7k Views 1 Watching
  • 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.
  • O Offline
    O Offline
    oracle3001
    wrote on last edited by
    #1

    I am using QSettings to parse an ini file, which works fine except for one particular entry in the ini file (which I don't control).

    [Key]
    KeyValue=7,10|4,6|3,3|2,2|

    using

    @QSettings settings(cfgPath, QSettings::IniFormat);
    settings.beginGroup("Key");
    QString KeyValue_= settings.value("KeyValue", "").toString();
    qDebug() << KeyValue_ ;@

    but this fails to return the value. All other values of a more traditional form Var = Value. I presume it is something to do with the way QSettings parses this, is there anyway around it?

    Also, the ini file starts with a general section.

    [General]

    The parser returns values from this outside of a beginGroup, but not if I do a setting.beginGroup("General") ?

    e.g.

    Works
    @QString regCode_ = settings.value("RegistrationCode", "").toString();
    qDebug() << regCode_ ;@

    Doesnt' work
    @settings.beginGroup("Database");
    QString regCode_ = settings.value("RegistrationCode", "").toString();
    qDebug() << regCode_ ;
    settings.endGroup();@

    Finally, is there a simple way to test for the existence of a particular setting (beyond doing a settings.value, with default value "" and testing for that? The ini file I am parsing may or not have any combination of the following keyvalues.

    [Key]
    KeyValue1=7
    KeyValue2=10
    KeyValue3=22
    ...
    KeyValueX

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rahul Das
      wrote on last edited by
      #2

      @ QSettings settings(cfgPath, QSettings::IniFormat);
      settings.beginGroup("Key");
      QString PlayerRanges_ = settings.value("KeyValue", "").toString();
      qDebug() << KeyValue_ ;
      @

      In this,what is "KeyValue_" ?


      Declaration of (Platform) independence.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rahul Das
        wrote on last edited by
        #3

        @ QSettings settings(cfgPath, QSettings::IniFormat);
        settings.beginGroup("Key");
        QString PlayerRanges_ = settings.value("KeyValue", "").toString();
        qDebug() << KeyValue_ ;
        @

        In this,what is "KeyValue_" , that you are trying to debug in line 4 ?


        Declaration of (Platform) independence.

        1 Reply Last reply
        0
        • O Offline
          O Offline
          oracle3001
          wrote on last edited by
          #4

          Updated code (was a typo when simplifying my code to post)....still have the same problem described in OP i.e that keyValue when in the more complex form isn't captured by QSettings.value.

          1 Reply Last reply
          0
          • N Offline
            N Offline
            NicuPopescu
            wrote on last edited by
            #5

            Hi,

            @QString PlayerRanges_ = settings.value("KeyValue", "").toString();
            qDebug() << KeyValue_ ;@

            you print out something else ... the conversion to QString just works if string is with quote

            @[Key]
            KeyValue="7,10|4,6|3,3|2,2|"@

            bq. The parser returns values from this outside of a beginGroup, but not if I do a setting.beginGroup(“General”) ?

            is silly but I ask: you sure update and read the right .ini file? :) ... beginGroup should just work nicely :)

            1 Reply Last reply
            0
            • O Offline
              O Offline
              oracle3001
              wrote on last edited by
              #6

              I don't have control of the ini file / not my ini to go changing (it is a 3rd party app)...so I can't put 7,10|4,6|3,3|2,2| in quotes.

              bq. is silly but I ask: you sure update and read the right .ini file? :) … beginGroup should just work nicely :)

              Yes, as all the other info is being parsed correctly.

              1 Reply Last reply
              0
              • N Offline
                N Offline
                NicuPopescu
                wrote on last edited by
                #7

                try toStringList() which split the input value by comma ... then concatenate them or what you'd need

                @QStringList KeyValue = settings.value("KeyValue", "").toStringList();@

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  ScottR
                  wrote on last edited by
                  #8
                  1. This is why you should just cut & paste the working code instead of trying to write code on the fly in the comment box.

                  2. settings.value() is returning a QStringList. You can probably use join() to get the original value.

                  I found this out by writing this code:
                  QVariant x = settings.value("KeyValue", "");
                  and inspecting x in a debugger.

                  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