This is another one of those "which way is best" questions. I am wondering which is the best way to use named constant QStrings in a class. For example:

Qt Code:
  1. class MyClass {
  2. public:
  3. void doStuff() {
  4. {
  5. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", "MySpecialDbName");
  6. //do all sorts of database stuff here
  7. db.close();
  8. }
  9. QSqlDatabase::removeDatabase("MySpecialDbName");
  10. }
  11. };
To copy to clipboard, switch view to plain text mode 

"MySpecialDbName" should be a named constant, right? Especially if doStuff() is complex or the call to removeDatabase() is done in another method etc.

One way I thought of is to use an enum and a function to translate the enum to a QString.
Qt Code:
  1. enum MyStrings {
  2. DbName,
  3. SettingsGroup,
  4. ProgramName
  5. };
  6. QString getMyString(MyStrings string) {
  7. switch (string) {
  8. case (DbName):
  9. return QString("MySpecialDbName");
  10. case (SettingsGroup):
  11. return QString("my/config/db");
  12. case (ProgramName):
  13. return QString("My Program");
  14. default:
  15. return QString();
  16. }
  17. }
To copy to clipboard, switch view to plain text mode 

Or even the enum as above and an array of QStrings or a QStringList.

Maybe I'm just being pedantic but I can't seem to find any examples of what other people do. And maybe it doesn't matter in the end anyway... but I figured I'd ask.