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

Posts: 47
Registered: ‎01-26-2011
My Device: Not Specified
Accepted Solution

Passing variable from QML to WebView

[ Edited ]

So I have a QML file like so


Container {
    id: cont
    property variant numArray: ["1","2","3","4","5"]
	WebView {
	    id: webView
	    html: "<html><head>" +
	    "<script type='text/javascript' src='assets/js/pie.js'></script>" +
            onCreationCompleted: {


and the pie.js has the following



In the QML file, the WebView signal, 'onCreationCompleted', does print out the correct value.


However in the JS file, the numArray variable isn't written to the page.


My code isn't exactly like this, but the structure is the same. How can I go about passing the QML variable to the JS file inside the WebView?



Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Passing variable from QML to WebView

Properties won't be directly exposed to a webpage. To communicate with WebView you'll need to call webView.postMessage(....) and implement navigator.cascades.onmessage handler on HTML page as shown on this page:


WebView's docs have another example for returning the data from WebView in similar way.


Andrey Fidrya, @zmeyc on twitter
Posts: 262
Registered: ‎07-13-2012
My Device: PlayBook, DA B, DA C, LE Z10 #102, Q10, Z30
My Carrier: T-Mobile

Re: Passing variable from QML to WebView

Using the method in this tutorial should work: http://www.bbcascades.com/index.php/tutorial-list/52-passing-information-to-html-from-qml

Check out my BB10 Cascades Coding site: BBcascades.com & Cascades Blog: bbcascadescode.tumblr.com

My Built for BlackBerry app: The Dive Plan