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
Gerry_BB
Posts: 38
Registered: ‎12-06-2011
My Device: Playbook 64GB, Curve 9360, BB Z10 LE
My Carrier: Koodo
Accepted Solution

Access QML label in C++

Hi,

 

I am wondering how I can access a label I have in a QML file in C++. Previously I had the label in main.qml and was able to access in this way :

main.qml 

 

property alias currTimeText: currTime.text

 c++

mRoot->setProperty("currTimeText", timeString);

 

However, I have restructured my qml so that the label is no longer inside of main.qml. Now main.qml has a button which pushes a page in another qml file and that page contains my label. This makes the issue more complicated. Note that in the c++ code above mRoot is created from main.qml. Any help is appreciated! 

 

Thanks,

 

Gerry

Please use plain text.
Developer
Dredvard
Posts: 160
Registered: ‎01-27-2012
My Device: Playbook
My Carrier: Rogers

Re: Access QML label in C++

If you want to get access to an object from c++  assign it an objectName

Label{
    id:labelid
    objectName:"labelname"
    text: "text"
}

 So from c++

 

you can  find and access the object directly using

    mNavPane = qml->createRootObject<NavigationPane>();	
Label *label = mNavePane->findChild<Label*>("objectName");
label->setText(labelText);

 

---
If you find my post helpful please "like" it and "accept as a solution"
Please use plain text.