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

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
Posts: 116
Registered: ‎10-31-2012
My Device: BB10 Dev Alpha B
My Carrier: -

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

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

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. Smiley Happy

Maz