[Qt-interest] javascript does not load in QWebview

Tony Rietwyk tony.rietwyk at rightsoft.com.au
Thu Mar 10 12:20:42 CET 2011


Hi Karthick, 
 
I don't think QWebView.load is synchronous - although the 4.6.0 docs doesn't
explicitly say either way!  You need to let the event loop spin for the view
to access the network, etc.  
 
I suggest to add a slot and connect to the view's loadFinished().  Then you
can check whether the load worked, and evaluate your Javascript.  
 
Hope that helps, 
 
Tony.
 
 

Sent: Thursday, 10 March 2011 14:49
 
 Hi All, 
I am trying to execute the javascript  through evaluate javascript() call in
QWebview. while calling evaluate javacript() call in Qt, the returned value
from that call is null. how to make  javascript works in Qwebview?
please help me to solve this issue?


Qt code: 

QWebView *view;
view->load(QUrl("file:///home/admin/test.html"));
Qvariant name, address;
name = view->page()->mainFrame()->evaluateJavaScript("abc()");
qDebug() << name.toString();       //getting null value
address = view->page()->mainFrame()->evaluateJavaScript("getroute()");
qDebug() << address.toString();   //getting null value


test.html:
<html>
<head>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false"></script> //This is
for calling google maps api's
<script type="text/javascript">


function abc()
{
     return "SUCCESS";
}
var address;   //global variable


function getroute()
{
    /*
       declaration and initialization of google maps api stuff
   */
    calling google api directionsService.route(req, function(resp,status){
    if (status == ok)
    {
        address = resp.routes[0].legs[0].start_address;
    } });
   return address;
} 
</script>
<body>
</body>
</html>
-- 
Regards,
Karthick

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110310/c6899f7d/attachment.html 


More information about the Qt-interest-old mailing list