Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QString as parameter in switch case
Indrajeet last edited by
Is there any way to use QString as a parameter in switch case as shown below.
dbzhang800 last edited by
You can use an string as the condition of switch statement, as long as the string class provide an operator such as:
operator int() const
But, you cannot code something like this!!
From ISO C++ 6.4:
The value of a condition that is an initialized declaration in a switch statement is the value of the declared variable if it has integral or enumeration type, or of that variable implicitly converted to integral or enumeration type otherwise.
From ISO C++ 6.4.2
Any statement within the switch statement can be labeled with one or more case labels as follows:
case constant-expression :
where the constant-expression shall be an integral constant.