Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
oddboy
Posts: 136
Registered: ‎05-24-2011
My Device: Z30 running 10.2 and Playbook 4GLTE running OS2.1
My Carrier: rogers
Accepted Solution

why is my switch case not working?

hey gang,

 

i have a switch statement, but it doesn't seem to work.  when the selectedIndex for a DropDown changes, the console.log statements fire, but the currentFlashMode never gets updated.

 

currentFlashMode is a "property variant currentFlashMode" on the navigationPane root element on another page.  this switch/case is on a secondary page that gets pushed.

 

if i use if/else instead, everything works fine.

 

i.e., this doesn't work:

 

                   switch (selectedIndex) {
console.log("entering switch/case for selectedIndex.."); case 0: // console.log(" -->App: FlashModeSelector, On"); currentFlashMode = 0; break; case 1: // console.log(" -->App: FlashModeSelector, Off"); currentFlashMode = 1; break; case 2: // console.log(" -->App: FlashModeSelector, Auto (default)"); currentFlashMode = 2; break; case 3: // console.log(" -->App: FlashModeSelector, Light"); currentFlashMode = 3; break; }

 but this does:

 

if (selectedIndex == 0) {
                    	currentFlashMode = 0;
                    	console.log(" ------------>App: in onSelectedIndexChanged, currentFlashMode is : " + currentFlashMode);
                    }
                    if (selectedIndex == 1) {
                        currentFlashMode = 1;
                    }
                    if (selectedIndex == 2) {
                        currentFlashMode = 2;
                    }
                    if (selectedIndex == 3) {
                        currentFlashMode = 3;
                    }

 

What am I doing wrong here?

 

 

bron: a cron-like scheduler for BlackBerry 10
http://apps.oddelement.com
Please use plain text.
Developer
steve_web
Posts: 319
Registered: ‎05-07-2009
My Device: BlackBerry Z10, PlayBook, 9900
My Carrier: Telus

Re: why is my switch case not working?

If you move your first console log statement out and put it before the switch statement does it work?

I think you need to have the case statement right after the switch.

PlayBook Apps: DataMine, Dots + Boxes, 5 Marbles
BlackBerry SmartPhone Apps: 5 Marbles Soon: **** (D.Z.A), ****Quest, **** Challenge, VaultCracker, DevBrowser, Radial****
Please use plain text.
Developer
oddboy
Posts: 136
Registered: ‎05-24-2011
My Device: Z30 running 10.2 and Playbook 4GLTE running OS2.1
My Carrier: rogers

Re: why is my switch case not working?

Well, the thing is that each of the console log lines work. When I change the drop down to 1, the console log line prints that the selectedIndex changed to 1, but the currentFocusMode variable doesn't get changed..
bron: a cron-like scheduler for BlackBerry 10
http://apps.oddelement.com
Please use plain text.
Developer
Zmey
Posts: 1,510
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: why is my switch case not working?

Hi,

 

This is a known bug in Qt 4 (fixed only in Qt 5):

http://supportforums.blackberry.com/t5/Native-Development/Strange-switch-behaviour-in-QML/m-p/228142...

 

Only the first line of each 'case' statement is executed. Qt incorrectly turns the second statement into return.

Workaround: wrap every case into { } or use if/else instead.

 

More info on Qt bug tracker:

https://bugreports.qt-project.org/browse/QTBUG-17012

 


Andrey Fidrya, @zmeyc on twitter
Please use plain text.