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
Developer
strobejb
Posts: 276
Registered: ‎10-15-2012
My Device: bb10 developer

QmlDocument::setContextProperty() not available in Sheet?

[ Edited ]

I use the following to make my Cascades C++ application instance available to QML code:

 

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

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

the "_myApp" object is available in all of my QML files that are included by main.qml - except from within Sheets, where I get the following error:

 

ReferenceError: Can't find variable: _myApp

 

My Sheets are included as attachedObjects in my mail.qml. Has anyone noticed this before? Is there a workaround?

Please use plain text.
Developer
strobejb
Posts: 276
Registered: ‎10-15-2012
My Device: bb10 developer

Re: QmlDocument::setContextProperty() not available in Sheet?

I think I narrowed the problem down - 

 

I was attempting to use the _myApp object from within a ListItemComponent (which was inside a sheet). I think it is the ListItemComponent that is preventing this scope problem

 

I temporarily fixed the issue by doing this in my main.qml:

 

onCreationCompleted: {

  Qt._myApp = _myApp;

}

 

And then I use Qt._myApp from within the ListItemComponent.  Not great, because I have to fixup a whole bunch of locations in QML and JS files, but at least I have a workaround now

 

 

Please use plain text.