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
Contributor
homerguy
Posts: 10
Registered: ‎05-14-2013
My Device: Z10
My Carrier: Bell
Accepted Solution

How to send C++ object to body of SystemToast

Hello,

 

I am trying to send the value of my C++ object to the SystemToast body property through QML.

 

I have done the steps to register the C++ object to QML via the setContextProperty method. It works as I am able to pass the value (which is of type QString) to a QML label's text property.

 

When I run the app, the SystemToast pops up with blank text.

 

Any suggestions?

 

Thanks

 

 

Please use plain text.
Developer
jalue
Posts: 196
Registered: ‎03-04-2013
My Device: BB Z10
My Carrier: Rogers

Re: How to send C++ object to body of SystemToast

Could you post that chunk of code for your SystemToast { } ?   

Please use plain text.
Contributor
homerguy
Posts: 10
Registered: ‎05-14-2013
My Device: Z10
My Carrier: Bell

Re: How to send C++ object to body of SystemToast

Sure

 

SystemToast {
     id: myQmlToast
     body: cppObject.value
}

 

Please use plain text.
Developer
simon_hain
Posts: 16,010
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: How to send C++ object to body of SystemToast

did you expose the value using Q_PROPERTY? If the value changes, did you add a NOTIFY to the property?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
homerguy
Posts: 10
Registered: ‎05-14-2013
My Device: Z10
My Carrier: Bell

Re: How to send C++ object to body of SystemToast

Yep I did, I've actually tested it by passing cppObject.value to a
Label {} I placed on a container and it works fine. When i try to do the same on the body attirbute of SystemToast it seems to do nothing.
Please use plain text.
Developer
Zmey
Posts: 1,511
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: How to send C++ object to body of SystemToast

That's very strange. Could you post the entire QML file?

Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Contributor
homerguy
Posts: 10
Registered: ‎05-14-2013
My Device: Z10
My Carrier: Bell

Re: How to send C++ object to body of SystemToast

Sure

 

        Page {
            id: listPage

            content: Container {
                Label {
                	text: cppObject.value  // This Works
                }

                ListView {
                    id: deviceList
                    dataModel: GroupDataModel {
                        grouping: ItemGrouping.None
                    }

                    listItemComponents: [
                        ListItemComponent {
                            type: "listItem"
                            StandardListItem {
                                title: ListItemData.Device + ' - ' + ListItemData.OS
                                textFormat: TextFormat.Auto
                                
                                contextActions: [
                                    ActionSet {
                                        title: "More"
                                        ActionItem{
                                            title: "Verify"
                                            onTriggered: {
                                                myQmlToast.show()
                                            }
                                            attachedObjects: [
                                                SystemToast {
                                                    id: myQmlToast
                                                    body: cppObject.value // This Doesn't Work
                                                }
                                            ]
                                        }
                                        
                                    }
                                ]
                            }
                        }
                    ]

                    function itemType(data, indexPath) {
                        return "listItem";
                    }
                }
            }

            attachedObjects: [
                DataSource {
                    id: serviceDataSource
                    source: cppObject.value
                    type: DataSourceType.Json
                    onDataLoaded: {
                        deviceList.dataModel.clear();
                        deviceList.dataModel.insertList(data)
                    }
                }
            ]

        }

 

Please use plain text.
Developer
simon_hain
Posts: 16,010
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: How to send C++ object to body of SystemToast

this is related to the scope of the listitemcomponent, it does not have access to the cppObject as it has a different scope.

you could register it globally or create a function on the listview which is accessible by the listitemcomponent.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
homerguy
Posts: 10
Registered: ‎05-14-2013
My Device: Z10
My Carrier: Bell

Re: How to send C++ object to body of SystemToast

Ah right, it is a different scope. Thanks

How would I go about to register it globally, or make a function.

Please use plain text.
Developer
simon_hain
Posts: 16,010
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: How to send C++ object to body of SystemToast

1. give the ListItemComponent an id, like "myID"
2. use "myID.ListItem.view" to access the ListView
3. create a property or function in the listview that accesses the cppObject
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.