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

Adding a javascript code (function) in webview from c++

HI,

 

I have to add javascript function in webview created by c++.

My webview in qml is like this

 

Page {
	Container {
		Webview {
			url: "local:///assets/firstpage.html"
			function calculate () {
				// some processing
			}
			onMessageReceived: {
				// some processing
			}
			onCreationCompleted: {
				// some processing
			}
		}
	}
}

 I need to create the same from c++

 

How to add the function and slot in webview from c++.

 

 

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Adding a javascript code (function) in webview from c++

There's a good explanation of how to do signals and slots in QML and the equivelant code in C++ here...

 

http://developer.blackberry.com/native/documentation/cascades/dev/signals_slots/

 

Basically you use the connect() function to tie them together.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 237
Registered: ‎05-21-2012
My Device: BlackBerry RED Z10
My Carrier: WiFi

Re: Adding a javascript code (function) in webview from c++

Why do you need so? It's really great and better to attach all Objects and UIs in QML and it's more easy.

 

Anyway try to look at this https://github.com/blackberry/Cascades-Samples/blob/master/cascadescookbookcpp/src/recipes/webviewre...

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Adding a javascript code (function) in webview from c++

Integration between C++ and QML (which also includes JavaScript) can be learned here...

 

http://developer.blackberry.com/native/documentation/cascades/dev/integrating_cpp_qml/


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 126
Registered: ‎06-25-2013
My Device: Z10
My Carrier: none

Re: Adding a javascript code (function) in webview from c++

I need to write the complete qml part in c++. and I have this code in my qml so I need to convert it into c++.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Adding a javascript code (function) in webview from c++

Okay so have a look at the links I gave you they have plenty of examples of what QML signals and slots look like, with an equivalent C++ example.

If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Adding a javascript code (function) in webview from c++

If you are asking to place your javascript function in C++ then of course this isn't possible, you would have to rewrite it in C++ as well.

If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 126
Registered: ‎06-25-2013
My Device: Z10
My Carrier: none

Re: Adding a javascript code (function) in webview from c++

So I need to write the javascript in c++. Is there any example for the same.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Adding a javascript code (function) in webview from c++

As I noted above you don't *need* to rewrite it, you can keep the function in a separate file and connect to it as you would in QML.

Asking for an equivalent when all we have to go on is a function name calculate() doesn't make a lot of sense, obviously there is a lot of similarity in most coding languages and so whatever's in that function you would expect to port easily to C++.

If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 1,178
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: Adding a javascript code (function) in webview from c++

Have to disagree with this. Yes it is easier for newbies to do in QML/JavaScript, but we don't know how complicated that "some processing" is. JavaScript is interpreted, C++ is compiled. Although JavaScript engines are getting faster all the time, they will never truly compete with compiled C++ for performance.

 

I also find that Momentics is much better at debugging C++ than JavaScript in QML.


nemory wrote:

Why do you need so? It's really great and better to attach all Objects and UIs in QML and it's more easy.

 

Anyway try to look at this https://github.com/blackberry/Cascades-Samples/blob/master/cascadescookbookcpp/src/recipes/webviewre...




 

 



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.