0

I have a qt app with a qwebview that is using a google maps, there is no problem while initializing google maps; but when i try to add a marker like this:

ui->webView->page()->mainFrame()->evaluateJavaScript(QString("addmarker(-34.659639, -58.468231);"));

I get QVariant(Invalid).

My javascript code is as follows:

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
  var map;
  var marker;

  var myLatlng = new google.maps.LatLng(-34, -58);

  function initialize() {
    var myOptions = {
      zoom: 14,
      center: new google.maps.LatLng(-34, -58),
      mapTypeId: google.maps.MapTypeId.HYBRID,
      zoomControl: true,
      zoomControlOptions: { style: google.maps.ZoomControlStyle.SMALL },
    };

    map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);

  } 
  // Add a marker to the map and push to the array.
  function addmarker(location) {
    var Latlng = new google.maps.LatLng(location);
    marker = new google.maps.Marker({
    position: Latlng,
    map: map,
    title: "marker"
  });

  }

Please can any one help with this? Thanks in advance, Regards

AGG88
  • 196
  • 4

1 Answers1

2

It might be related to this post: evaluateJavaScript in PyQt - function is not called

There is a signal in QT that is emitted when the page is finished loading, called loadFinished().

Please have a look and see if the webview.loadFinished signal can fix it.

Community
  • 1
  • 1
Jake W
  • 2,788
  • 34
  • 39