[Qt-interest] how to exchange value between javascript and Qwebview?
noam.rosenthal at nokia.com
noam.rosenthal at nokia.com
Tue Mar 8 05:17:06 CET 2011
hi
The problem is in your js code. you define the 'address' variable as local inside a function, and then return it from outside that function.
have you tried running the function from within js? I suspect that this is not a Qt issue at all.
No'am
----- Original message -----
> Hi All,
>
> I am trying to execute javascript through QWebview. when i am returning
> value from javascript to Qwebview, the returned value is printing null.
> I got stuck here.
> if anyone knows, please tell me how to return that value to Qt?
>
> My Qt code:
> ......
> name1=
> webView->page()->mainFrame()->evaluateJavaScript("calcRoute('germany',
> 'france')");
> qDebug()<< "The I result is" << name1.toString(); //printing NULL
> .......
>
> My Javascript code:
> <html>
> <script type="text/javascript"
> src="http://maps.google.com/maps/api/js?sensor=false"></script>
> <script type="text/javascript">
> ..........
> var directionsService = new google.maps.DirectionsService();
> function initilaize()
> {
> directionsDisplay = new google.maps.DirectionsRenderer();
> var chicago = new google.maps.LatLng(41.850033, -87.6500523);
> var myOptions = {
> zoom:7,
> mapTypeId: google.maps.MapTypeId.ROADMAP,
> center: chicago
> }
> map = new google.maps.Map(document.getElementById("map_canvas"),
> myOptions);
> directionsDisplay.setMap(map);
>
> directionsDisplay.setPanel(document.getElementById("directionsPanel"));
> }
>
> function calcRoute(start, end) {
> var address;
> var directions = new Array();
> var request = {
> origin:start,
> destination:end,
> travelMode: google.maps.DirectionsTravelMode.DRIVING
> };
> directionsService.route(request, function(response, status); {
> if (status == google.maps.DirectionsStatus.OK) {
> //directionsDisplay.setDirections(response);
> var address = response.routes[0].legs[0].start_address;
> }
> });
> return address;
> }
> </script>
> <body onload="initialize()">
> ........
> </body>
> </html>
>
> --
> Regards,
> Karthick
>
>
>
>
>
>
>
>
>
>
>
>
<Attachment> ATT00001..txt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110308/fea84917/attachment-0001.html
More information about the Qt-interest-old
mailing list