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
Posts: 80
Registered: ‎09-03-2012
My Device: 9810
My Carrier: Vodafone
Accepted Solution

Conversion of QObject to respective control object (Native App Development With Cascades API)

I am accessing a control object (a button) defined in QML as object of type QObject in my app.cpp file.

 

QObject *click_btn = root->findChild<QObject*>("click_button");

 

Can I convert this to type Button  so that i can make its use in connect method. Is it possible ?

Always Success
Developer
Posts: 849
Registered: ‎03-03-2011
My Device: Z10

Re: Conversion of QObject to respective control object (Native App Development With Cascades API)

[ Edited ]

It should be simple:

Button *click_btn = root->findChild<Button*>("click_button");

 

Or:

QObject *click_btn = root->findChild<QObject*>("click_button");

Button *b = qobject_cast<Button*>(click_btn);

 

About qobject_cast:

It attempts to cast its argument to the pointer type specified in angle-brackets, returning a non-zero pointer if the object is of the correct type (determined at run-time), or 0 if the object's type is incompatible. So it is also useful to check if the type is correct.

--------------------------------------------------------------------------------------
Leader of Ljubljana BlackBerry Developer Group
BlackBerry Certified Builder for Native Application Development
Highlighted
Developer
Posts: 80
Registered: ‎09-03-2012
My Device: 9810
My Carrier: Vodafone

Re: Conversion of QObject to respective control object (Native App Development With Cascades API)

[ Edited ]

I too did the same thing but was making error while using Object types.

 

Thanks for the reply



Always Success