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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.