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
jcnielsen
Posts: 90
Registered: ‎06-03-2009
My Device: Dev Alpha B
Accepted Solution

Use QML ImageView in C++

Hi

I can see how to use a ImageView, or any other QML declared object, declared in QML from the constructor method that creates the scene using the QML document and then sets the AbstractPane root. But how do I access an ImageView from anywhere else in the same class? Shall I keep a reference to the root or the QML-document?

Br
J. C. Nielsen

Attended DEVCON 2010

Free Tibet
Please use plain text.
Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Use QML ImageView in C++

You can call Application::instance()->scene() and cast it to your top level object type, something like this:

Page *appPage = (Page *)Application::instance()->scene();
Camera *camera = appPage->findChild<Camera *>("myCamera");
etc

Or keep the pointer to appPage and/or other controls in member variables. This way the code will be cleaner.

Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Developer
jcnielsen
Posts: 90
Registered: ‎06-03-2009
My Device: Dev Alpha B

Re: Use QML ImageView in C++

Thanks for the tip. I think I will go for the solution with keeping references to the few objects I need.

Br
J. C. Nielsen

Attended DEVCON 2010

Free Tibet
Please use plain text.
Trusted Contributor
Brennan12325
Posts: 204
Registered: ‎05-15-2012
My Device: None

Re: Use QML ImageView in C++

Yeah, your best bet is to just keep a reference to your AbstractPane then use findChild

ListView *redditCommentsList = m_AbsPane->findChild<ListView*>("commentsList");
----------------------
Check out my app, Alien Flow for reddit

And of course, like my post if you found it helpful or informative!
Please use plain text.