Solved why enum has problems in qt ?
-
i gave tried many codes to work with enum in qt but always fail
can anyone please help me -
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
-
Could you paste in an example that isn't working for you?
-
i have problem like that
i have a class calling shared .h file
with 2 enumsenum 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 -
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...
-
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
-
@VRonin Thank you for your advice
-
@aran Thank you aran