Hi, I am recieving a string that defines the function i have to call. To do this I wrote this class:
Qt Code:
  1. class MiTableClass:public QObject
  2. {
  3. Q_OBJECT
  4. Q_ENUMS(MiTableElements);
  5.  
  6. //This is a singleton class but i deleted the extra code lines for this post.
  7.  
  8. public:
  9. int indexOf(QString);
  10. QString commandNumber(int);
  11.  
  12. enum MiTableElements
  13. {
  14. //Eth commands
  15. AUTOTEST,//0
  16. HALT,//1
  17. STANDBY,//2
  18. SSNORMAL,//3
  19. };//The enum is way longer
  20. };
  21.  
  22. int MiTableClass::indexOf(QString command)
  23. {
  24. const QMetaObject metaObject=m_Instance->staticMetaObject;
  25. int index = metaObject.indexOfEnumerator("MiTableElements");
  26. QMetaEnum metaEnum = metaObject.enumerator(index);
  27. int i=metaEnum.keyToValue(command.toLatin1());
  28. return i;
  29. }
  30.  
  31. QString MiTableClass::commandNumber(int nCmd)
  32. {
  33. const QMetaObject metaObject=m_Instance->staticMetaObject;
  34. int index = metaObject.indexOfEnumerator("MiTableElements");
  35. QMetaEnum metaEnum = metaObject.enumerator(index);
  36. QString str=metaEnum.valueToKey(nCmd);
  37. return str;
  38. }
To copy to clipboard, switch view to plain text mode 

and the to use it I do this
Qt Code:
  1. void HLP_MessageProcessor::run()
  2. {
  3. MiTableClass * mi =MiTableClass::Instance();
  4. lst=message.split(",");
  5.  
  6. //Figuring out the command code
  7. int i=mi->indexOf(lst[0]);
  8. switch(i)
  9. {
  10. case 0://AUTOTEST
  11. AUTOTEST_Function();
  12. break;
  13. case 1://HALT
  14. HALT_Function();
  15. //The lack of break here is on purpouse
  16. case 2://STANDBY
  17. STANDBY_Function();
  18. }
  19. }
To copy to clipboard, switch view to plain text mode 
Now the thing is that I will have to add cases inbetween the ones i already have and I would like to be able to write
Qt Code:
  1. switch(i)
  2. {
  3. case AUTOTEST:
  4. ...
To copy to clipboard, switch view to plain text mode 
And i do not know where to declare the enum so I can use it in this way for the switch.

So far i tried to put it as a global enum, but then the class members that compare the string with the enum value stopped to work.
Any ideas?
How to register the global enum inside my class? i'm lost in this topic