Alex Rivera | Logout

How to add Google Maps in my application in Qt?

Asked 2011-12-15T05:34:29.883
19

I am developing an application where I am in need of adding the Google map into our application. I am using Qt with UI design and I am not using QML. Is there any API for Qt for symbian or any file to be added to port into my app?

Edit
Report

1 Answer

2

I've been working on my university project in Qt using Google Maps as the main widget. Basically, it's best to load an external HTML file into QWebView which contains javascript code necessary to load the map. This practice lets you define javascript functions inside HTML file that can control the map (markers, etc) which you can then easily call in your Qt code. There is one catch though. When you load the map into your QWebView widget you will not be able to interact with it at all. To get rid of this problem you will need to create a class that inherits QWebPage that fakes user agent, for example:

class myWebPage : virtual public QWebPage
{
    virtual QString userAgentForUrl(const QUrl& url) const
    {
        return "Chrome/1.0";
    }
};

You will need to create a class that inherits QWebView and set this class' main page to new instance of the class myWebPage. Next step is to add a QWebView widget in your Designer. Promote this widget to your custom QWebView class. You will then have a fully functional map.

answered 2012-05-29T21:28:06.753

Your Answer