Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved how to read INI file and put into the array

    General and Desktop
    3
    8
    1460
    Loading More Posts
    • 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
      victor wang last edited by

      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!

      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @victor wang last edited by

        @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 Reply Quote 0
        • V
          victor wang @jsulm last edited by

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

          jsulm J.Hilk 2 Replies Last reply Reply Quote 0
          • jsulm
            jsulm Lifetime Qt Champion @victor wang last edited by

            @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 Reply Quote 1
            • J.Hilk
              J.Hilk Moderators @victor wang last edited by

              @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

              Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

              1 Reply Last reply Reply Quote 0
              • V
                victor wang @jsulm last edited by

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

                jsulm 1 Reply Last reply Reply Quote 0
                • jsulm
                  jsulm Lifetime Qt Champion @victor wang last edited by

                  @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.Hilk 1 Reply Last reply Reply Quote 0
                  • J.Hilk
                    J.Hilk Moderators @jsulm last edited by

                    @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

                    Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

                    1 Reply Last reply Reply Quote 1
                    • First post
                      Last post