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
- }
- break
- case match2: {
- step1
- step2
- step3
- }
- break
- default: {
- 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…
5 replies
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: 100
- property 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.
Hi,
This problem was mentioned in this [qt-project.org] post
You must log in to post a reply. Not a member yet? Register here!
