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: 42
Registered: ‎05-02-2013
My Device: Q10
Accepted Solution

Call qml functions in main.qml of Ui part from the headless part of application.

Hi all;

 

I wanted to make my application work in the background (Headless) But encountered several problems, first of all calculation are in qml functions (in main.qml: updateUi() with call javascript file *.js), who can I call them from the headless part when the UI part is closed by the user? please help me if you have any solution.

Thanks very much.

BlackBerry Development Advisor
Posts: 247
Registered: ‎07-14-2008
My Device: Not Specified

Re: Call qml functions in main.qml of Ui part from the headless part of application.

[ Edited ]

You cannot call qml code of your UI or any code of your UI directly from the headless app. The headless portion runs in its own process. There are however a few ways to enable communication between the headless and the UI portion:

1. Invocation framework.: UI can invoke the headless directly but headless caanot invoke the UI. So essentially this is a one way communication if that's what you need.

2. Local sockets: whenever the UI is launched, it can connect to the headless via local sockets and have a 2 way chat with each other.

3. FileSystem: This is also 2-way. Headless can write something to a file and the UI can listen for changes via QFileSystemWatcher and vice versa.

As stated above, you can communicate between the two but if you are looking for using application logics, algorithms, functions of each other, that is not possible. They are independent applications packaged in the same bar file.

 

Please read more here: https://developer.blackberry.com/native/documentation/cascades/device_platform/headless_apps/

Developer
Posts: 42
Registered: ‎05-02-2013
My Device: Q10

Re: Call qml functions in main.qml of Ui part from the headless part of application.

Hi;

Thank for your help

 

So it's not possible.

 

Excuse me but all work of my application is done by js function and qml.

 

Can I but a js function in *.js or *.qml file in headless part of my application project and call it from c++ file existing in headless part?

 

Please help me; Thanks

 

 

Developer
Posts: 16,495
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Call qml functions in main.qml of Ui part from the headless part of application.

there are certain libraries that execute javascript from c++, but i would suggest to port the code to c++ (in general).

see
https://stackoverflow.com/questions/2713289/how-to-execute-javascript-function-in-c
----------------------------------------------------------
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
Developer
Posts: 42
Registered: ‎05-02-2013
My Device: Q10

Re: Call qml functions in main.qml of Ui part from the headless part of application.

If I have understand all:  headless part of application in BB10 can't content qml file but only c++?

Can you confirm that?

If yes that main I must rewrite completely my application that have took me many months to finished it!!!!!

Developer
Posts: 16,495
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Call qml functions in main.qml of Ui part from the headless part of application.

yes.
that should have been clear that an application part without UI cannot execute code that is in the UI.
----------------------------------------------------------
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
Developer
Posts: 42
Registered: ‎05-02-2013
My Device: Q10

Re: Call qml functions in main.qml of Ui part from the headless part of application.

So what you suggest to me if my application is all in qml

to make it headless

Developer
Posts: 16,495
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Call qml functions in main.qml of Ui part from the headless part of application.

identify what processing you need for the headless part and migrate that to c++/Qt.
----------------------------------------------------------
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
Developer
Posts: 42
Registered: ‎05-02-2013
My Device: Q10

Re: Call qml functions in main.qml of Ui part from the headless part of application.

Thanks very much for your help.

Developer
Posts: 42
Registered: ‎05-02-2013
My Device: Q10

Re: Call qml functions in main.qml of Ui part from the headless part of application.

Please Another question:

 

Can  headless part read settings write <QSettings> by Ui part?