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: 126
Registered: ‎06-25-2013
My Device: Z10
My Carrier: none
Accepted Solution

Javascript function call from c++

Hi,

     

     I need to call a javascript function from c++ code. i have a webview in which a html page is open. 

     i can communicate to c++ from js using  navigator.cascades.postMessage . i need to call vice versa.

     i.e. c++ to js now.

 

Regards

 

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Javascript function call from c++

The introductory paragraphs in the WebView documentation mentions both postMessage and a way of communicating in the opposite direction.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 96
Registered: ‎06-05-2012
My Device: Developer
My Carrier: Developer

Re: Javascript function call from c++

[ Edited ]

Hi,

You have to use signals in c++. And connect this signal into QML where you created WebView.


Thanks,

Developer
Posts: 126
Registered: ‎06-25-2013
My Device: Z10
My Carrier: none

Re: Javascript function call from c++

Hi, 

  My JavaScript is in another file named as pagename.js . I need to execute the function in that js script continuously, like every 5 seconds. So my control needs to be here in c++.

 

Regards,

 

Developer
Posts: 126
Registered: ‎06-25-2013
My Device: Z10
My Carrier: none

Re: Javascript function call from c++

I need to call JavaScript continuously from c++ every 5 secs. And with postMessage I can call only once ?

Developer
Posts: 96
Registered: ‎06-05-2012
My Device: Developer
My Carrier: Developer

Re: Javascript function call from c++

Hi,

 

I tried alternate way to call JavaScript function continue in every 5 seconds.

Steps:

 

1. import .js file im QML.

2. create one function in QML and call java script function from QMLfunctuion.

3. emit signal from CPP in every 5 seconds and connect that signal to function in QML from whare you calling java script function.

4.  it will call indirectly java script function.

 

Thanks,

Anand

 

Highlighted
Developer
Posts: 126
Registered: ‎06-25-2013
My Device: Z10
My Carrier: none

Re: Javascript function call from c++

[ Edited ]

Hi,
How to emit a signal from c++ and receive it in qml. i tried it but was unable to get it.

I did the following.

 

in applicationui.hpp:

            created a signal

                             signals: void emitJsCall(QString);

in applicationui.cpp              

              void ApplicationUI::callJs(){

                      // wrote my stuff

                      emit emitJsCall(param); // throws an exception Object::connect: No such signal ApplicationUI::emitJsCall (param) in ../

              }

 

 

My call goes to jsvascript but all the functions are not working, like alert , window  ... How to make then work here ??


Regards;