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
Contributor
Dhanya
Posts: 21
Registered: ‎09-23-2012
My Device: BB10 Dev Alpha Device

How to access QML from CPP???

Hi,

I have a few set of questions

a)

              In my application, I have three qml files

 

1) main.qml  - which have a Navigation Page

2) x.qml         - which is a Segmented Control having an action item in it. When clicked on the action item displays the third qml file .

3) y.qml         - which is a Sheet .In the sheet I have a Text Field . 

 

I have only the originally created cpp files  ie. main.cpp , app.cpp , app.hpp

 

The text field value should be saved into an xml file dynamically.How can I do this?

 

 

b) 

                        If in the above mentioned third file ie. y.qml I have given an object name for the text field .Then how can I access the text field from the already existing cpp files  ie. main.cpp , app.cpp , app.hpp

                                 

            Whether I should make another cpp file for accessing the text field using the object name . If yes, how will I connect/access the newly made cpp file with the corresponding qml file( ie. y.qml) 

 

I am really confused with the whole thing and is seriously stuck.

 

Please :Helpsmilie:   :Helpsmilie:

Please use plain text.
Developer
kanaksony
Posts: 571
Registered: ‎04-11-2009
My Device: BB 10 Dev Alpha

Re: How to access QML from CPP???

Hi Dhanya,

 

First go through following links, it will clear all your doubts..

 

https://developer.blackberry.com/cascades/documentation/dev/integrating_cpp_qml/index.html

 

http://doc.qt.digia.com/qt/qtbinding.html

Regards,
Kanak Sony
------------------------------------------------------------------------------------------
http://dodevelopnshare.wordpress.com/ | http://www.linkedin.com/profile/view?id=188131481&trk=tab_pro
Please use plain text.
Contributor
Dhanya
Posts: 21
Registered: ‎09-23-2012
My Device: BB10 Dev Alpha Device

Re: How to access QML from CPP???

Hi Kanak,

 

Thank you for the reply

 

In the first link you provided,  gives only the case of the main.qml file and its corresponding class files.
But in my case, I have to get values from the third qml file which donot have its corresponding class files.
How can I get value from the third qml file in app.cpp?

 

If possible can you provide me some sample code .

 

Regards,

Dhanya

 

 

Please use plain text.
Contributor
Dhanya
Posts: 21
Registered: ‎09-23-2012
My Device: BB10 Dev Alpha Device

Re: How to access QML from CPP???

Hi,

I got the solution for getting text field value in another cpp file by using context property.  :smileyhappy:

Now how can I save this value along with system date into xml/json file??:Helpsmilie:

 

 

 

Regards,

Dhanya

 

Please use plain text.
Developer
kanaksony
Posts: 571
Registered: ‎04-11-2009
My Device: BB 10 Dev Alpha

Re: How to access QML from CPP???

If you have gone through above links carefully, you would have find, setContextProperty is alrady mentioned there... It will be good if you go thru QT docs..

Regards,
Kanak Sony
------------------------------------------------------------------------------------------
http://dodevelopnshare.wordpress.com/ | http://www.linkedin.com/profile/view?id=188131481&trk=tab_pro
Please use plain text.
Developer
simon_hain
Posts: 16,209
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to access QML from CPP???

you can find child elements of the root element by using (e.g.)

root->findChild<Sheet*>("splashSheet");

define the objectName property in your qml element to make it discoverable.

In this case:

 Sheet {
            objectName: "splashSheet"

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
djogon
Posts: 93
Registered: ‎10-29-2012
My Device: Z10

Re: How to access QML from CPP???

Dhanya - you keep saying "corresponding cpp file qhwn it comes to qml files". There is no direct association between the file and your "cpp" file. You load your qml tree and make instance of it.  then you can search the tree and modify objects within it with "findChild()" function for example.

 

I think that it would really go a long way if you would take some time to read the documentation. I found people here very helpful and patient, but the solution has to start with your willingness to learn by reading the documentation.

In addition - if you are not proficient in C++ - I would recommend tackling that first - it will really help you down the road.

 

Please use plain text.