[Qt-interest] how to exchange value between javascript and Qwebview?

Karthick sppkarthick at gmail.com
Mon Mar 7 12:37:40 CET 2011


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
*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110307/b00f5c85/attachment-0001.html 


More information about the Qt-interest-old mailing list