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
Regular Contributor
mazmellow
Posts: 77
Registered: ‎01-27-2010
My Device: Dev Alpha
My Carrier: Verizon
Accepted Solution

Why I can't accessing C++ object inside ListItemComponent.onCreationCompleted ..?

Hi everyone, 

My application has an HTTP connecting for retrieve XML feeds and insert data to ListView by using DataSource and DataModel, and I want to listenning when each of its ListItem of ListView is created completely that for using a ListItemData  to my c++ object. Then I write my code like this

// In main.cpp 

int main(int argc, char **argv)

{

    Application app(argc, argv);

    new MyApp(&app);

    returnApplication::exec();

}

// In MyApp.cpp

MyApp::MyApp(bb::cascades::Application *app) :     //constructor

QObject(app) {

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

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

AbstractPane *pane = qml->createRootObject<AbstractPane>()

app->setScene(pane);

}

void MyApp::doMyFunction(const QString & someData){

      qDebug() << "YES!! "+ someData;

}


In main.qml
Page{

       Container{

                ListView {

                       dataModel: myDataModel

                       listItemComponents: [

                                ListItemComponent {

                                      type: "item"

                                      Container{

                                              onCreationCompleted: {

                                                      console.log("---- LISTITEM ONCREATION COMPLETED");

                                                      app.doMyFunction(ListItemData.someData);    //<<<  But console print about "Can't find variable "app"  "

                                              }

                                      }

                                }

                        ]

                }//end listview

       }//end container
       

       onCreationCompleted: {

            myDataSource.load();

       }

 

      attachedObjects: [

          GroupDataModel {

                id: myDataModel

            },

           DataSource {

                id: myDataSource

                source: "some url for get feeds.. bla bla"

                type: DataSource.Xml

                onDataLoaded: {

                    myDataModel.clear();

                    myDataModel.insertList(data);

            }

      ]

}

I try to run mycode. But a console is print about "Can't find variable: app ". How can I resolve this problem?  :smileysad:

Thank you for all suggestion.
Maz

Please use plain text.
Regular Contributor
mazmellow
Posts: 77
Registered: ‎01-27-2010
My Device: Dev Alpha
My Carrier: Verizon

Re: Why I can't accessing C++ object inside ListItemComponent.onCreationCompleted ..?

Anyone here?  I try to use c++ object from other where like Page.onCreateComplete and can accessing! But in ListItemComponent.onCreateComplete is not.

I think, Is this a bug from sdk?  :smileyindifferent:

Please use plain text.
Developer
kylefowler
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: Why I can't accessing C++ object inside ListItemComponent.onCreationCompleted ..?

[ Edited ]

Its because the listitem is not in the same document tree as Page really, it lives with the ListView and doesnt have direct access to Page's items.

What you can do is create a javascript function in the listview object, and then have the listitemcomponent call out to that which in turn can relay it to your context variable "app".

int listitemcomponent Add id:itemContainer to your container then
itemContainer.ListItem.view.someFunctionDefinedInTheListView(data)

in listview:

function somefunctiondefinedinlistview(data) {
app.doMyFunction(data)
}

Like all of my posts
Please use plain text.
Regular Contributor
mazmellow
Posts: 77
Registered: ‎01-27-2010
My Device: Dev Alpha
My Carrier: Verizon

Re: Why I can't accessing C++ object inside ListItemComponent.onCreationCompleted ..?

Many thanks to kylefowler!! :smileyvery-happy:   I don't know that the ListItemComponent can't direct access Page's items before. I just click like on your comment. Thank you very much!!

Maz

Please use plain text.
Contributor
bunny1985
Posts: 12
Registered: ‎11-13-2012
My Device: Z10, q10
My Carrier: freelancer

Re: Why I can't accessing C++ object inside ListItemComponent.onCreationCompleted ..?

could you show how exacly it should looks like?

i have something like this :

 listItemComponents: [
                        
                        ListItemComponent {
                            id: itemContainer
                             Container {
                                     layout: DockLayout {

 and 

DropDown {
property int foodid
horizontalAlignment: HorizontalAlignment.Right
verticalAlignment: VerticalAlignment.Center
preferredWidth: 60.0
selectedIndex:ListItemData.quantity 
onSelectedIndexChanged: {
var quantity = selectedIndex;
itemContainer.ListItem.view.eaten(foodid, ile);
}

and i get :

 Can't find variable: itemContainer

Please use plain text.
Developer
babakar
Posts: 696
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: Why I can't accessing C++ object inside ListItemComponent.onCreationCompleted ..?

Another question

 

 ListView {
                objectName: "customList"
                
                leftPadding: 20
                rightPadding: 20
                bottomPadding: 20
                topPadding: 20
                
            }

 

How can I using c++ add listitemcomponents to my listview? As I will parse json file and add ...

Please use plain text.
Developer
BBSJdev
Posts: 5,969
Registered: ‎07-05-2012
My Device: Playbook, Z10 LE, Dev Alpha C
My Carrier: Orange

Re: Why I can't accessing C++ object inside ListItemComponent.onCreationCompleted ..?

@babakar please don't add your own question to already solved threads. thanks.


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.