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: 53
Registered: ‎09-19-2012
My Device: 9700
My Carrier: China mobile

How to find objects in different qml files?

We use the following code to find a button:

    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
    root = qml->createRootObject<AbstractPane>();

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

 

But how to find a button in another qml file?

Developer
Posts: 116
Registered: ‎10-31-2012
My Device: BB10 Dev Alpha B
My Carrier: -

Re: How to find objects in different qml files?

Searching belongs to AbstractPane I think, so you would have to load the document into a (non-rendered) Page.  Something like:

 

QmlDocument *qml = QmlDocument::create("asset:///MyQmlDoc.qml");
if (!qml->hasErrors()) {
    Page *page = qml->createRootObject<Page>();
    if (page) {
        page->findChild("myButton");
    }
}

 

Developer
Posts: 237
Registered: ‎11-24-2012
My Device: Blackberry 10 Dev Alpha
My Carrier: Telkomsel

Re: How to find objects in different qml files?

Developer
Posts: 53
Registered: ‎09-19-2012
My Device: 9700
My Carrier: China mobile

Re: How to find objects in different qml files?

The problem is, If the page is not rendered, findChild() returns zero; If I use app->setScene(root), the app freezes.

And, even if my tabPane qml is rendered, only objects in the first tab can be found. Other objects in the other tabs get zero with findChild(). Although they are in the same qml file, just in different tab pages.