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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Super Contributor
Posts: 398
Registered: ‎01-12-2011
My Device: Q10
My Carrier: Fido

How to get a reference to the current Application from anywhere in my code?

[ Edited ]

I would like to know how to get a reference to the current Application through code. I would like to be able to access my NavigationPane on my applications main screen from anywhere in my code so that I can push and pop screens.

 

I guess I'm trying to do something like:

 

getApplication()->navPane->pop();

 

or

 

getApplication()->navPane->push(aDifferentPage);

 

Or am I going about the pushing and popping the wrong way? I undertsand the idea of pushing and popping screens from a NavigationPane, I would just like to know how to do this from any screen.

 

Any ideas??

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

Re: How to get a reference to the current Application from anywhere in my code?

If you look at the class hierarchy, above bb::cascades::Application you'll get to bb::Application and then QCoreApplication, where there's an instance() static method that does what you want.


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!
Highlighted
Super Contributor
Posts: 398
Registered: ‎01-12-2011
My Device: Q10
My Carrier: Fido

Re: How to get a reference to the current Application from anywhere in my code?

[ Edited ]

Thanks!

 

Could you show me an example of how I would create the reference??

 

Something like this??:

 

QCoreApplication *instanceOfApp = QCoreApplication.instance();

 

This doesn't work though.

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

Re: How to get a reference to the current Application from anywhere in my code?

Static methods are called on the class, so you don't need any reference to anything ahead of time.

Just do bb::cascades::Application::instance() and it should give you the reference to the global application object.

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

Re: How to get a reference to the current Application from anywhere in my code?

Or QCoreApplication::instance() ...

By the way, when reporting that something "doesn't work", please always include details like what error message you see. Otherwise people responding have to guess what you're doing/seeing.

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!
Super Contributor
Posts: 398
Registered: ‎01-12-2011
My Device: Q10
My Carrier: Fido

Re: How to get a reference to the current Application from anywhere in my code?

[ Edited ]

Sorry about not providing more info, it was a syntax error:

 

error: expected primary-expression before '.' token

 

I was trying to use the dot operator where I shoud've used ::

 

It seems to be working so far. Thanks alot for your help!