Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 811987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:07:56+00:00 2026-05-15T01:07:56+00:00

I’m building a Qt app with Python where you can point and click at

  • 0

I’m building a Qt app with Python where you can point and click at a (google) map and get the coordinates of the location. The map is shown through a QWebView loading a simple HTML page and the user can create markers by clicking. Screenshot of the widget after clicking on the map.

However, I’m having trouble to retrieve the just-clicked location coordinates back to Qt (so that I can use them as variables — and, for example, show them in the QLineEdits on the topleft corner above, as current location of the marker).

This is the relevant part of the HTML file:

<script type="text/javascript">
var map;
function initialize() { 
    var local = new google.maps.LatLng(-23.4,-40.3);
    var myOptions = {
        zoom: 5,
        center: local,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    } 
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    google.maps.event.addListener(map, 'rightclick', function(event) {
        placeMarker(event.latLng);
    });
}

function placeMarker(location) {
    var clickedLocation = new google.maps.LatLng(location);
    var marker = new google.maps.Marker({
        position: location,
        map: map
    });

    map.setCenter(location);
}

function dummyTxt() {
    return 'This works.';
}
</script>

I’ve been trying with evaluateJavaScript, but was not able to retrieve the coordinates. I tried to created a function to access the position with marker.getPosition(), but with no luck. The dummy below works though..

newplace = QWebView.page().mainFrame().evaluateJavaScript(QString('dummyTxt()'))

>>> print newplace.toString()
This works.

Any suggestions on how to get the coordinates back to Qt?

Edit:

Here is the code that worked for me:

def update_geo(self):
    # Capture coordinates of the last marker on the map.
    mark = self.map.page().mainFrame().evaluateJavaScript('document.getElementById("markerlocation").value').toString()
    # Convert string to list of floats, stripping parentheses.
    marker = str(mark).strip('()').split(', ')
    decimals = [float(c) for c in marker]

Full source in https://github.com/nelas/veliger/blob/master/veliger.py#L2374

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:07:57+00:00Added an answer on May 15, 2026 at 1:07 am

    I found a work around to make it work but I’m not pretty sure that it will be the right approach. Anyway, this is what I did:

    1. Create a hidden input in the body section of your html document to save the position data of the marker:

      <body>
          (...)
          <input id="locationData" type="hidden">
          (...)
      </body>
      
    2. In the javascript code, save the position of the marker in the hidden input every time it’s created:

      function placeMarker(location) {
          (...)
          document.getElementById("locationData").value = marker.position;
          (...)
      }
      
    3. In your Qt code, read the value of the hidden input with the instruction:

      webView->page()->mainFrame()->findFirstElement("#locationData").evaluateJavaScript("this.value").toString();
      

    I hope it helps!

    Source: http://opendocs.net/qt/4.6/webkit-formextractor.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 397k
  • Answers 398k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would take a look at the indexes on Table1.… May 15, 2026 at 3:27 am
  • Editorial Team
    Editorial Team added an answer A SQL statement is a string, but you have to… May 15, 2026 at 3:27 am
  • Editorial Team
    Editorial Team added an answer Take a look at the AppDomain.UnhandledException event The event handler… May 15, 2026 at 3:27 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.