Switch case problem
-
Hello all,
in QML is it necessary to wrap body of case in curly brackets.??
let's say,
@
switch (arg) {
case match1: {
step1
step2
step3
}
breakcase match2: {
step1
step2
step3
}
breakdefault: {
step1
step2
step3
}
break
}
@because if i don't use brackets, execution of case is carried out only for first step and remaining steps are skipped...
-
This is probably a bug in the expression rewriter. Basically, in QML, most JavaScript expressions pass through an expression rewriter (depending on the situation; eg, a binding like: property int a: {some expression} gets rewritten as property int a: (function(){return {some expression} }).
There are a few things in JavaScript which are tricky - switch statements and the "with" statement spring to mind immediately.
If you have a simple reproduction for this issue, please create a bug report and assign it to me, I'll take a look at it.
Cheers,
Chris. -
if i write,
@
Item {
width: 100
height: 100property int count: 0 Component.onCompleted: { switch (count) { case 0: console.log ("1: count is zero") console.log ("2: count is zero") console.log ("3: count is zero") break default: console.log ("1: count is non zero") console.log ("2: count is non zero") console.log ("3: count is non zero") break } }
}
@here i haven't used any brackets and hence i am not getting 2nd and 3rd console log prints, if i use brackets it prints.
-
same here, in a .qml file, only the first line in a case block will be execute. However, in a .js file there is no such problem
-
Yeah, the contents of .js file imports are (after .pragmas and .imports are stripped out) passed directly to a JavaScript engine, and thus don't suffer the same "rewriting" fate as expressions in .qml files.
Thanks for the simple repro, I'll look into this.
-
Hi,
This problem was mentioned in "this":http://qt-project.org/forums/viewthread/9897/ post