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
New Developer
laxad
Posts: 24
Registered: ‎12-08-2012
My Device: Z10 Ferrari Red

Cannot access c++ context property in different qml

I have

 

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

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

 

in Testingnew.hpp.

 

In main.qml I can access app.initiateRequest() <-- an invokable function

However, in AllEventsPage.qml I cannot access app.initiateRequest()

 

Any idea how I can make this happen?

 

Thanks,

Daxal

Developer
bobdodd
Posts: 116
Registered: ‎10-31-2012
My Device: BB10 Dev Alpha B

Re: Cannot access c++ context property in different qml

You need to set the contextProperty for each document that you render. It goes with the document/page, not the whole UI.

New Developer
laxad
Posts: 24
Registered: ‎12-08-2012
My Device: Z10 Ferrari Red

Re: Cannot access c++ context property in different qml

Alright, so do I have to do something like this:

 

    qml = QmlDocument::create("asset:///main.qml").parent(this);
    qml->setContextProperty("app", this);

    // create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();

 

   //THIS IS ADDED PART
    page = root->findChild<Page*>("pageobjectname");

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

 


Do I have to fetch a Page in the qml document or can I fetch a qml document from findChild?

 

Regular Contributor
mazmellow
Posts: 77
Registered: ‎01-27-2010
My Device: Dev Alpha

Re: Cannot access c++ context property in different qml

HI laxad,

Can you provide your qml code when you call c++ object? Last week, I found a way that can't call c++ directly. Maybe that happen on you. :smileyhappy:

Maz