[Qt-interest] QWebView: getting events from javascript
Lukas Lipavsky
llipavsky at suse.cz
Tue Jul 21 17:32:40 CEST 2009
Hi,
I'm working on a simple application, which would display different maps of
same location in same scale. When I change scale or location on one map,
others should change it automatically as well.
I'm trying to solve a following problem.
I have a (Qt 4.5) QWebView object which displays following page with google map:
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var map;
function changed() {
***MAP CHANGED***
}
function initialize() {
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
google.maps.event.addListener(map, 'bounds_changed', changed);
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>
I am able to control the map from the outside with
qwebview->page()->mainFrame()->evaluateJavaScript(). But I need also
the other way. When the user drags a map or changes the zoom level, the
map object triggers a bounds_changed event, which I can process inside
javascript (shown in the code above). Is there some way to "propagate"
it from javascript to the QWebView so I can handle it in the Qt application?
I've found only one possible solution so far - polling: the event in
javascript sets some js variable and Qt application polls this variable
in regular time intervals...
Is there any better way?
TIA
Best regards,
--
Lukas Lipavsky, QA Developer
GPG Key ID: FF55774A
Key fingerprint = 5BEB 6AF2 9653 638E EC0E 7E73 9A11 2BC5 FF55 774A
---------------------------------------------------
SUSE LINUX, s.r.o. e-mail: llipavsky at suse.cz
Lihovarska 1060/12 tel: +420 284 028 969
190 00 Prague 9
Czech Republic
---------------------------------------------------
More information about the Qt-interest-old
mailing list