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
Forum Update on Monday, May 27th 2025

how to read INI file and put into the array

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 1.8k 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 10 Mar 2017, 03:18 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!

    J 1 Reply Last reply 10 Mar 2017, 05:20
    0
    • V victor wang
      10 Mar 2017, 03:18

      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!

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 10 Mar 2017, 05:20 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 10 Mar 2017, 06:01
      0
      • J jsulm
        10 Mar 2017, 05:20

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

        V Offline
        V Offline
        victor wang
        wrote on 10 Mar 2017, 06:01 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?

        J J 2 Replies Last reply 10 Mar 2017, 06:05
        0
        • V victor wang
          10 Mar 2017, 06:01

          @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 Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 10 Mar 2017, 06:05 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 10 Mar 2017, 06:20
          1
          • V victor wang
            10 Mar 2017, 06:01

            @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 Offline
            J Offline
            J.Hilk
            Moderators
            wrote on 10 Mar 2017, 06:07 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
            • J jsulm
              10 Mar 2017, 06:05

              @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 10 Mar 2017, 06:20 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?

              J 1 Reply Last reply 10 Mar 2017, 06:29
              0
              • V victor wang
                10 Mar 2017, 06:20

                @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?

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 10 Mar 2017, 06:29 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 1 Reply Last reply 10 Mar 2017, 06:44
                0
                • J jsulm
                  10 Mar 2017, 06:29

                  @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 Offline
                  J Offline
                  J.Hilk
                  Moderators
                  wrote on 10 Mar 2017, 06:44 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

                  1/8

                  10 Mar 2017, 03:18

                  • Login

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