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
dtater
Posts: 158
Registered: ‎01-11-2010
My Device: 9700 | 9900 | PlayBook | Dev Alpha
Accepted Solution

togglebutton setChecked() causing application to freeze and then SIGSEGV

Hey all.  I've begun development on my first Cascades / C++ application in my spare time (full time job is BB java developer).

 

 

I've got a question that i hope somebody can help me out with.

 

In my main constructor, after i have loaded in teh QML document, i make a call to get a pointer to the QML object.  In this particular case, it's a toggle switch.

 

// toggle switch
mToggle = root->findChild<ToggleButton*>("tab1_toggle");

 

and later in the app, when a user touches another part of the screen or uses a menu item, i fire off a method that contains this code:

 

mToggle->setChecked(false);

 

This code always causes the application to freeze, then the OS terminates it with the folowing printed in console

 

SIGSEGV code=1 fltno=11 ip=791f13f2(/base/usr/lib/libbbcascades.so.1@+0x35a9a) mapaddr=000f13f2. ref=00000010

 

Why? 

 

- - - - - - - - - -
BlackBerry Development Advisor (Retired)
mgoulet
Posts: 329
Registered: ‎05-07-2012
My Device: BB Alpha

Re: togglebutton setChecked() causing application to freeze and then SIGSEGV

Hi,

 

Simpe question: Are you certain that mToggle is valid from your findChild method? is the "tab1_toggle" specifier the "objectName" or the "id" in your QML docuent?

 

Martin

Developer
dtater
Posts: 158
Registered: ‎01-11-2010
My Device: 9700 | 9900 | PlayBook | Dev Alpha

Re: togglebutton setChecked() causing application to freeze and then SIGSEGV

[ Edited ]

what do you mean when you say 'findChild method' ?

 

And yes, i do believe that it is a valid.  Here's the portion of the QML that the toggle lives in

 

                Container {
                    id: tab1_contToggle
                    layout: StackLayout {
                    }
                    topMargin: 65
                    layoutProperties: StackLayoutProperties {
                        horizontalAlignment: HorizontalAlignment.Center
                    }
                    ToggleButton {
                        id: tab1_toggle
                        onCheckedChanged: {
                            //I can put code here to get triggered w/o problems when the switch is toggled
                        } // end of tab1_ toggle element
                    } // end of tab1_contRoot
                } // end of tab1

 Here is the hpp file where mToggle is declared.

 

private:

// toggle switch
	ToggleButton *mToggle;

// other UI elements here that work just fine from other bits of code..

 

- - - - - - - - - -
Developer
iamjay
Posts: 18
Registered: ‎04-28-2012
My Device: Playbook & Dev Alpha

Re: togglebutton setChecked() causing application to freeze and then SIGSEGV

You need to set objectName of the ToggleButton not id for findChild() to work.

 

ToggleButton {
    id: tab1_toggle
    objectName: "tab1_toggle"
}

 

BlackBerry Development Advisor (Retired)
mgoulet
Posts: 329
Registered: ‎05-07-2012
My Device: BB Alpha

Re: togglebutton setChecked() causing application to freeze and then SIGSEGV

dtater,

 

1) I was referring to the findChild method that you posted in your code block:

// toggle switch
mToggle = root->findChild<ToggleButton*>("tab1_toggle");

2) You said that you believe the mToggle variable is valid. Can you validate this with a null check? Also, initialize the pointer to 0 at the beginning of your applicaiton (before you try setting it with findChild)

 

3) iamjay's comment is valid, you must use the 'objectName' for reference in your C++ code.

 

Let me know when you've tried this out!

 

Martin

Developer
dtater
Posts: 158
Registered: ‎01-11-2010
My Device: 9700 | 9900 | PlayBook | Dev Alpha

Re: togglebutton setChecked() causing application to freeze and then SIGSEGV

Ah.  Thanks for the tip about the objectName rather than the id.  That fixed it. 

 

If this is the case, what is the difference between objectName and id?

 

THANKS; your post iamjay was mared as solution.

- - - - - - - - - -
Developer
dtater
Posts: 158
Registered: ‎01-11-2010
My Device: 9700 | 9900 | PlayBook | Dev Alpha

Re: togglebutton setChecked() causing application to freeze and then SIGSEGV

Thanks for your suggestions, mgoulet!  Thanks for pointing out that i forgot to initialize the variables to null.  Before I started this thread, I was doing a null check as a diagnostic, but that was returning *not* null... Because I was not initializing the variables correctly.

 

iamjay's solution fixed it.

 

Thanks to both of you!

- - - - - - - - - -
BlackBerry Development Advisor (Retired)
mgoulet
Posts: 329
Registered: ‎05-07-2012
My Device: BB Alpha

Re: togglebutton setChecked() causing application to freeze and then SIGSEGV

Excellent!

 

Let us know if you need anything else and we'll try to point you in the correct direction.

 

Martin

Developer
Pumano-
Posts: 215
Registered: ‎11-05-2011
My Device: Z10

Re: togglebutton setChecked() causing application to freeze and then SIGSEGV

"id" for using object from QML, "objectName" for handling using C++
Developer
dtater
Posts: 158
Registered: ‎01-11-2010
My Device: 9700 | 9900 | PlayBook | Dev Alpha

Re: togglebutton setChecked() causing application to freeze and then SIGSEGV

Just curious as to why we have *two* different things tha do the *same* thing. Who thought that was a good idea?
- - - - - - - - - -