Check the loading of URL in QWebview
-
Hello everybody,
I use a Qwebview to load a local URL to display a map. I want to check if the url is correctly loaded, that means the map is actually displayed.
I tried to use the signal loadfinished of Qwebview but the argument is true even when the map is not displayed.
I'm not sure that signal is able to do what I want. Is there another way to check the loading of the url ?Thanks for your answer,
-
If the map is loaded asynchronously (e.g. AJAX) there is no way to detect it easily. That's because the onLoaded event of the page was fired long before the map has finished loading. You either have to detect it in your page yourself with some JavaScript magic (and then you can call a slot in C++) or you have to overwrite the QNetworkAccessManager to be in control of http request.
-
Thanks for your reply.
I use the seturl method of Qwebview. I could'nt find in the QT manual if the loading is asynchronously. I guess it is.
I don't know well what Javascript magic is and I don't want to overload my program with an external tool.
Than, what do you mean by "overwrite the QNetwokAccessManager to be in control of http request" ? Is it a part of your Javascript magic based solution ?Otherwise, is there another way to fix that problem ?
Thanks
-
With "asynchronous loading" I do not mean the way setUrl() works.
You say you load a local URL, this means that this html page is in your hands and you know what this page does. You have to detect if this page asynchronously loads the map (I guess so). If this is the case you have to modify your page in such a way, that your page knows when loading the map is finished. Up till here, these changes do not have anything to do with QtWebKit, they are only pure HTML and JavaScript. And because I do not know how your page works, I just called it JavaScript magic :-)
As soon as you have modified your page in the described way, you can then call some C++ slot if this is necessary.The second way to solve this, could be to overwrite the QNetworkAccessManager class of Qt (it has nothing to do with the above solution). I recommend to read some documentation on QNetworkAccessManager. You have to know some stuff about http requests to properly use this second solution.
I would give a try to the first solution, because that's more independent. With independent I mean, that you could use that page in any browser and in any browser you would detect that the map was no loaded.
-
Ok. I didnt' understand what you meant.
I'm not an expert about javascript and html. Then, you think checking the loading is enable by modifing the html script and linking the html event with a QT slot. I don't see how it can be done. Here is the html code:
@<HTML >
<html>
<head><title></title></head>
<body>
[removed][removed]
<div id="mapdiv"></div>
[removed]
var options = {
controls: [
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoom(),
new OpenLayers.Control.Attribution()
]
};
map = new OpenLayers.Map("mapdiv",options);
map.addLayer(new OpenLayers.Layer.OSM());
var proj = new OpenLayers.Projection("EPSG:4326");
var lonLat = new OpenLayers.LonLat( -0.6447 ,44.8430 ).transform(proj, map.getProjectionObject());var zoom=16;
var vector_layer = new OpenLayers.Layer.Vector('Polygon Layer');
map.addLayer(vector_layer);map.setCenter (lonLat, zoom);
[removed]</body>
</html>@
NB : I don't know why [removed] replace script item when I paste the code. The first ones stand for including the "http://www.openlayers.org/api/OpenLayers.js".Anyway thanks for your help,