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
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

How would you discover all Cascades QML globals?

In exploring issues related to another thread, I discovered that at least one name that's available in the Javascript global namespace under Cascades is neither documented as being there nor even visible if you enumerate the names in the global object.  Background is in this post http://supportforums.blackberry.com/t5/Cascades-Development/Doing-all-of-JSON-from-QML/m-p/1906645#M...

 

In short, I've discovered that there's a name Application available, with useful members available, but it's neither documented directly as being available, nor can I (currently) tell how you'd discover programmatically that it was there. (To those who immediately thought "of course Application is available!", please slow down and read the whole post... you may be jumping to conclusions.)

 

Additional info:

# this code generates the following output:
console.log('Application is ' + Application);
console.log('Application properties: ' + Object.getOwnPropertyNames(Application));

Application is bb::cascades::Application(0xef4f4)
Application properties: unixSignal,objectName,applicationName,organizationName,awake,mainWindow,
fullscreen,organizationDomain,thumbnailp,aboutToQuit,applicationVersion,invisible,lowMemory,
urlHandlerInvoked,quit,swipeDown

Now it's rather obvious this is the singleton instance of the Application class from C++. One could retrieve it by calling Application::instance().  That's not the question...

 

I've checked the headers, and it's not specified as such in the docs either.

 

So the basic question: if I hadn't stumbled over this, how else could I have found it?

 

I ask it that way partly to learn what ought to be fixed... docs? headers?

 

Perhaps more usefully in the bigger picture: are there other such "hidden" globals that would be useful to us?


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Retired
Posts: 499
Registered: ‎05-07-2012
My Device: developer
My Carrier: developer

Re: How would you discover all Cascades QML globals?

nm, perhaps.

Are you sure about bb:cascades::Application?  Most apps will declare a global for this (except Qt apps)

 

Stuart

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: How would you discover all Cascades QML globals?

I'm not sure what you mean by the question. What I showed above is the output from the code itself, so when I asked it to write "Application is " + Application, that's what it output. Clearly somewhere in there, the name "Application" in the QML global JavaScript context is being mapped to the singleton instance of the bb::cascades::Application class.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Retired
Posts: 499
Registered: ‎05-07-2012
My Device: developer
My Carrier: developer

Re: How would you discover all Cascades QML globals?

Yes, i retract my question.  I'd misread your post.

(I don't have my full environment here. The only global I can think of is Application, and it seems reasonable to be exposed.  Is this related to any setContextProperty and qmlRegisterType calls you make, or is this done behind the scenes?)

 

Stuart

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: How would you discover all Cascades QML globals?

The native code involved is just the main.cpp stub from, I believe, the basic Momentics Cascades template, and app.cpp looks like this:

App::App()
{
    QmlDocument *qml = QmlDocument::create("../../../shared/misc/Dev1/main.qml");
    AbstractPane *root = qml->createRootNode<AbstractPane>();
    Application::setScene(root);
}

Wherever "Application" is coming in, it's nothing I'm registering.

 

I agree it seems reasonable for the global "Application" instance to be exposed, and I suspect somewhere in the Cascades source there is something that's doing just that. I'm basically wondering whether that's documented somewhere (and if so, where) or whether it's undocumented, and also whether there are any others like it that we should be able to use.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!