[Qt-interest] javascript does not load in QWebview

Gopalakrishna Bhat gopalakbhat at gmail.com
Thu Mar 10 19:03:42 CET 2011


Hi Karthick,

According to me the function abc() in not called so it returns a " " . You
can try putting a alert('hello') in abc() and see if it is displayed.

 If you can tell what you are trying to achieve then some one might be able
to help here.

BTW if you are trying to execute javascipt only you can try

name = view->page()->mainFrame()->evaluateJavaScript("function
abc(){alert('This page has finished loading!');return 'he'} abc();");

alternatively you can put

function abc(){alert('This page has finished loading!');return 'he'} abc();

into a separate file and read it

http://doc.qt.nokia.com/4.7.1/webkit-fancybrowser.html contains an example
of how to do this.

With regards,
Gopalakrishna

On Thu, Mar 10, 2011 at 9:18 AM, Karthick <sppkarthick at gmail.com> wrote:

> 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
> *
>
>
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
>


-- 
My blog http://gkbhat.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110310/09afe845/attachment-0001.html 


More information about the Qt-interest-old mailing list