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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Highlighted
Developer
Posts: 188
Registered: ‎09-03-2012
My Device: Blackberry 10
Accepted Solution

Cannot access context property from inside ListView checkbox - onCheckedChange event

I have a context property call "app" that links to my C++ application. My listview has a checkbox with onCheckedChange event listener. In that method, when I make a app.runAction call to the application C++ side., the system displays cannot find app error.

 

If I move the Checkbox outside of the list view, it will trigger app.runAction correctly.

 

Could you please take a look? Thanks!

 

C++ side on how I defined the context property.

 

    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

    if (qml->hasErrors()) {
        return false;
    }

    qml->setContextProperty("app", this);

    navigationPane = qml->createRootObject<NavigationPane>();
    if (!navigationPane) {
        return false;
    }

 

QML Side

 

NavigationPane {
    id: nav

Page {
        id: mainPage
        Container {

ListView {    

listItemComponents: [
        ListItemComponent {
                        type: "item"
                        Container {

                   CheckBox {
                                // Determine whether the CheckBox should be checked
                                // according to a value in the data model
                                checked: ListItemData.checked
                                onCheckedChanged: {
                                     app.testAction();
                                }
                            }

Developer
Developer
Posts: 174
Registered: ‎03-05-2009
My Device: Dev Alpha
My Carrier: -

Re: Cannot access context property from inside ListView checkbox - onCheckedChange event

it is a scoping issue...i really hope that the devs find a way to fix that properly aside from this ugly solution:

 

you can solve this by setting your app variable into the global object Qt

 

NavigationPane {
    id: nav

onCreationCompleted: Qt.app = app

Page {
        id: mainPage
        Container {
ListView {    
listItemComponents: [
        ListItemComponent {
                        type: "item"
                        Container {
                   CheckBox {
                                // Determine whether the CheckBox should be checked
                                // according to a value in the data model
                                checked: ListItemData.checked
                                onCheckedChanged: {
                                     app.testAction();
                                     Qt.app.testAction();
                                }
                            }

 

any code within a ListItemComponent will suffer from this 'scoping' issue Smiley Sad

Developer
Posts: 188
Registered: ‎09-03-2012
My Device: Blackberry 10

Re: Cannot access context property from inside ListView checkbox - onCheckedChange event

That works! Thanks lew!
Developer
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: Cannot access context property from inside ListView checkbox - onCheckedChange event

I would argue that you probablly shouldnt use the Qt global scope, but who knows.

 

You can always access the list view from your listitemcomponent and could put a function in there that acts a proxy to your context property

 

componentId.ListItem.view.myFunction()

Like all of my posts