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. why enum has problems in qt ?
Forum Updated to NodeBB v4.3 + New Features

why enum has problems in qt ?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 1.6k 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.
  • M Offline
    M Offline
    MIDO_QT
    wrote on 20 Apr 2017, 20:39 last edited by
    #1

    i gave tried many codes to work with enum in qt but always fail
    can anyone please help me

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 20 Apr 2017, 21:13 last edited by VRonin
      #5

      This is not a Qt problem but general C++ syntax. use enum class instead of enum

      Also please take a look at https://stackoverflow.com/help/how-to-ask for future posts. Other people might have the same problem you have in the future and it would be nice for them to be able to just google it and find it on this forum

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      M 1 Reply Last reply 20 Apr 2017, 21:27
      1
      • C Offline
        C Offline
        Chris Hennes
        wrote on 20 Apr 2017, 20:45 last edited by
        #2

        Could you paste in an example that isn't working for you?

        Chris Hennes, Pioneer Library System

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MIDO_QT
          wrote on 20 Apr 2017, 20:49 last edited by VRonin
          #3

          i have problem like that
          i have a class calling shared .h file
          with 2 enums

          enum x 
          {
          a=3, 
          b=6,
          c
          }
          enum y
          {
          a=10, //error
          b=3,//error
          d//no error
          }
          

          and how can i call the both enums in that class
          using thier values

          1 Reply Last reply
          0
          • A Offline
            A Offline
            aran
            wrote on 20 Apr 2017, 21:10 last edited by
            #4

            Even though you call the two enums different names ('x' and 'y'), there members live in the same namespace, i.e., you redeclare 'a' and 'b' in the second enum. That doesn't work. It is kinda the same as declaring a variable 'a' twice in the same scope, that also doesn't work... If you have to use the same name 'a' and 'b' in both enums, the only way to really accomplish that (iirc) is to wrap them in different namespaces outside of the class definition. A better solution, though, would be to simply use different names...

            M 1 Reply Last reply 20 Apr 2017, 21:32
            0
            • V Offline
              V Offline
              VRonin
              wrote on 20 Apr 2017, 21:13 last edited by VRonin
              #5

              This is not a Qt problem but general C++ syntax. use enum class instead of enum

              Also please take a look at https://stackoverflow.com/help/how-to-ask for future posts. Other people might have the same problem you have in the future and it would be nice for them to be able to just google it and find it on this forum

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              M 1 Reply Last reply 20 Apr 2017, 21:27
              1
              • V VRonin
                20 Apr 2017, 21:13

                This is not a Qt problem but general C++ syntax. use enum class instead of enum

                Also please take a look at https://stackoverflow.com/help/how-to-ask for future posts. Other people might have the same problem you have in the future and it would be nice for them to be able to just google it and find it on this forum

                M Offline
                M Offline
                MIDO_QT
                wrote on 20 Apr 2017, 21:27 last edited by
                #6

                @VRonin Thank you for your advice

                1 Reply Last reply
                0
                • A aran
                  20 Apr 2017, 21:10

                  Even though you call the two enums different names ('x' and 'y'), there members live in the same namespace, i.e., you redeclare 'a' and 'b' in the second enum. That doesn't work. It is kinda the same as declaring a variable 'a' twice in the same scope, that also doesn't work... If you have to use the same name 'a' and 'b' in both enums, the only way to really accomplish that (iirc) is to wrap them in different namespaces outside of the class definition. A better solution, though, would be to simply use different names...

                  M Offline
                  M Offline
                  MIDO_QT
                  wrote on 20 Apr 2017, 21:32 last edited by
                  #7

                  @aran Thank you aran

                  1 Reply Last reply
                  0

                  1/7

                  20 Apr 2017, 20:39

                  • Login

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