Hi guys,

I'm trying to use values in my database as arguments for functions e.g. I have a column with colours e.g. red, blue etc and I would like to use these values as arguments into a function.

In my header file, I've got #define red 7 etc etc, however the only way that I can think of using the database values would be a conversion function such as:

Qt Code:
  1. int MyClass::Conversion(QString sDatabaseColumnText)
  2. {
  3. switch(sDatabaseColumnText)
  4. case "red":
  5. {
  6. return 7;
  7. }
  8. }
To copy to clipboard, switch view to plain text mode 

and then my function would just have:

Qt Code:
  1. function(Conversion(query.value(0).toString();
To copy to clipboard, switch view to plain text mode 

I haven't compiled the code so I'm not sure if there are syntax errors, but it's the ideas that I'm more interested in.

I obviously don't want to create a table in my database whereby I have an 'int' value assigned to my values, because this will double up my #defines and it's prone to errors and becomes an updating nightmare.

EDIT P.S. I just remembered that cases can only use ints so my use of strings won't work, but anyway, imagine that I change my example to a bunch of 'if' statements.