Switch case in Qt
-
the Swtich case x ... y is not working in Qt.
it gives missing ; error.
How to use multiple sequential Cases for ex: case 1 ... 100
-
the Swtich case x ... y is not working in Qt.
it gives missing ; error.
How to use multiple sequential Cases for ex: case 1 ... 100
@dan1973 said in Switch case in Qt:
How to use multiple sequential Cases for ex: case 1 ... 100
And further to @jsulm C++ does not support this (e.g. "ranges") in a
switch...caseanyway. C++ is not, say, Python with amatchstatement. For a range in C++ you'll want to write something likeif (x >= 1 && x <= 100)rather than aswitch-case.P.S.
it gives missing ; error.
Then your C++ code is incorrect, nothing to do with Qt.
-
the Swtich case x ... y is not working in Qt.
it gives missing ; error.
How to use multiple sequential Cases for ex: case 1 ... 100
@dan1973 said in Switch case in Qt:
How to use multiple sequential Cases for ex: case 1 ... 100
Good luck with writing a separate case for every number :))
(No, don't try that. For your use-case there are other options in C++. You may consider even a simple if - statement)As previously being said, there is no such
switch-casein C++.See here for further info.
Type
condition can only yield the following types:
-
integral types
-
enumeration types
-
class types
If the yielded value is of a class type, it is contextually implicitly converted to an integral or enumeration type.
If the (possibly converted) type is subject to integral promotions , the yielded value is converted to the promoted type. -