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. how to read INI file and put into the array

how to read INI file and put into the array

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 1.7k 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.
  • V Offline
    V Offline
    victor wang
    wrote on last edited by
    #1

    Hi, i'm using Qt5.5 on my embedded linux computer.
    It is my code here

    I wanna put childkey and values into array.
    Then compare them.
    But i don't know how to do it.
    Please Help!

    jsulmJ 1 Reply Last reply
    0
    • V victor wang

      Hi, i'm using Qt5.5 on my embedded linux computer.
      It is my code here

      I wanna put childkey and values into array.
      Then compare them.
      But i don't know how to do it.
      Please Help!

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @victor-wang Then put them into your array. What exactly is the problem?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      V 1 Reply Last reply
      0
      • jsulmJ jsulm

        @victor-wang Then put them into your array. What exactly is the problem?

        V Offline
        V Offline
        victor wang
        wrote on last edited by
        #3

        @jsulm
        I got a new way to solve but i got some problem here.
        This is my code here

        And i got errors here

        I'm trying to analyze the childkey.
        What else i can do to solve the problem of switch case?

        jsulmJ J.HilkJ 2 Replies Last reply
        0
        • V victor wang

          @jsulm
          I got a new way to solve but i got some problem here.
          This is my code here

          And i got errors here

          I'm trying to analyze the childkey.
          What else i can do to solve the problem of switch case?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @victor-wang You cannot use a string in switch - the error message actually says that.
          You can only use integers in switch. You either use if ... else if... or you convert your string keys to integers/enum values.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          V 1 Reply Last reply
          1
          • V victor wang

            @jsulm
            I got a new way to solve but i got some problem here.
            This is my code here

            And i got errors here

            I'm trying to analyze the childkey.
            What else i can do to solve the problem of switch case?

            J.HilkJ Online
            J.HilkJ Online
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @victor-wang

            The error messaged is quite clear,

            you're only allowed to use integers als switch key. Strings are not defined.

            You'll have to do write that yourself or go the old-fashioned way of

            if(){
            
            }else if{
            
            }else if{
            }
            ...
            

            Be warned however, comparing strings is not a fast process.


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            0
            • jsulmJ jsulm

              @victor-wang You cannot use a string in switch - the error message actually says that.
              You can only use integers in switch. You either use if ... else if... or you convert your string keys to integers/enum values.

              V Offline
              V Offline
              victor wang
              wrote on last edited by
              #6

              @jsulm
              Can you give me an example, i don't know how to do it.

              @J-Hilk
              I can just only use if...else if...else for instead?

              jsulmJ 1 Reply Last reply
              0
              • V victor wang

                @jsulm
                Can you give me an example, i don't know how to do it.

                @J-Hilk
                I can just only use if...else if...else for instead?

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @victor-wang How to use if? @J-Hilk already did. But here again:

                if (childKey == "aaa") {
                ...
                } else if (childKey == "bbb") {
                ...
                } else if...
                

                You can have an enum:

                enum MyEnum
                {
                   AAA,
                   BBB,
                   CCC,
                ....
                }
                
                // Ten a convert function
                MyEnum convert(QString key)
                {
                    if (childKey == "aaa") {
                        return AAA
                    } else if (childKey == "bbb") {
                       return BBB
                    } else if...
                
                }
                
                // then your switch
                MyEnum key = convert(childKey);
                switch(key)
                {
                    case AAA:
                        break;
                    case BBB:
                        break
                ...
                }
                

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                J.HilkJ 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @victor-wang How to use if? @J-Hilk already did. But here again:

                  if (childKey == "aaa") {
                  ...
                  } else if (childKey == "bbb") {
                  ...
                  } else if...
                  

                  You can have an enum:

                  enum MyEnum
                  {
                     AAA,
                     BBB,
                     CCC,
                  ....
                  }
                  
                  // Ten a convert function
                  MyEnum convert(QString key)
                  {
                      if (childKey == "aaa") {
                          return AAA
                      } else if (childKey == "bbb") {
                         return BBB
                      } else if...
                  
                  }
                  
                  // then your switch
                  MyEnum key = convert(childKey);
                  switch(key)
                  {
                      case AAA:
                          break;
                      case BBB:
                          break
                  ...
                  }
                  
                  J.HilkJ Online
                  J.HilkJ Online
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #8

                  @jsulm @victor-wang

                  Actually you dont have to go through the pain to define a convert-function

                  enum myEnum{/
                          AAA,
                          BBB,
                          CCC,
                          ...
                      };
                      Q_ENUM(myEnum)
                  
                  ...
                  QString s = StringFromSettings;
                  myEnum switchKey = static_cast<myEnum>(QMetaEnum::fromType<myEnum>().keyToValue(s.toLocal8Bit().data()));
                  
                  switch (switchKey){
                  case AAA:...break;
                  ...
                  default: .... break;
                  }
                  

                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  1

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved