I need to create the equivalent of a switch/case statement for strings in C++ with Qt. I believe that the simplest way is something like this (pseudo code)
enum colours { red, green, blue };
QString array[] colour_names = { "red", "green", "blue" };
switch (color_names[user_string]) {
case red: answer="Chose red";
case green: answer="Chose green";
case blue: answer="Chose blue";
other: answer="Invalid choice";
}
But this doesn't take advantage of some of the features of Qt. I've read about QStringList's (to find the position of the string in a list of strings), and std:map (see How to easily map c++ enums to strings which I don't fully understand).
Is there a better way to do a switch on strings?