简体   繁体   中英

How to put Javascripts for evaluation in evaluatejavascript function of QWebView

EDIT: Too many edits:doh:

I have identified the problem this time. There is a flaw in the way I am passing the Javascript code to the evaluatejavascript func. of QWebView.

Using Google maps's API, when I click a pushButton attached to the slot holding the below code

this->page()->mainFrame()->evaluateJavaScript (QString ("Open(%1,2)").arg ( point.x ()).arg (point.y ()) );

the map pertaining to the location in question gets displayed.

Now if I want to add a marker to a particular coordinate, I do:

this->page()->mainFrame()->evaluateJavaScript (QString ("addMarker (%1, %2)").arg (point.x ()).arg (point.y ()) );

This code doesn't execute. Any ideas?

Besides this, what is the way to add a user defined function to evaluateJavaScript for evaluation?

Finally found the answer!

Any Javascript function which has to be called from function evaluateJavaScript is supposed to be defined in an html file (included in) the C++ source, as shown below:

Now instead of creating a new add marker function, I have added its code in the Open function defined below:

var map;

function initialize()
{
      if (GBrowserIsCompatible()) 
      {
            map = new GMap2(document.getElementById("map"));
            map.setCenter( new GLatLng(0,0),1 );
      }
    }

function Open (x,y)
{
    map.setCenter (new GLatLng(x,y), 13);

    var point = new GLatLng (x,y);
    map.addOverlay (new GMarker(point));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM