Google Maps not displaying in WebView, other sites work



  • I just picked up Qt and QML for the first time and the first thing I wanted to get working was just to open Google Maps in a WebView but it doesn't work.

    Here's the QML:

    @import QtQuick 2.0
    import QtWebKit 3.0

    Rectangle {
    width: 1024
    height: 960
    WebView {
    width: 1024
    height: 960
    anchors.centerIn: parent
    url: "http://maps.google.com"
    }
    }
    @

    The window opens but the contents of the WebView are completely blank. If I try other websites then the correct web page is displayed.

    What's wrong with this code? I am not behind any proxy or firewall. I suspect it is something to do with HTTPS given that some maps APIs use HTTPS but I don't see why HTTP would work but not HTTPS.

    I am using Qt 5.1 on Windows 7 64-bit.



  • Anyone?

    This is my first look at Qt and it seems even the most basic thing does not work! Why?


  • Moderators

    You are probably correct that the issue is due to HTTPS. If you modify your code to probe for errors...
    @
    import QtQuick 2.0
    import QtWebKit 3.0

    WebView {
    width: 1024
    height:960
    url: "http://maps.google.com"

    Component.onCompleted: {
        onLoadingChanged.connect(report)
    }
    
    function report(loadRequest) {
        console.log(loadRequest.errorString)
    }
    

    }
    @
    ...you will probably see an error message like "Unable to init SSL Context".

    Qt cannot ship SSL libraries for legal reasons. From http://qt-project.org/doc/qt-5.1/qtnetwork/ssl.html :
    [quote]Due to import and export restrictions in some parts of the world, we are unable to supply the OpenSSL Toolkit with Qt packages. Developers wishing to use SSL communication in their deployed applications should either ensure that their users have the appropriate libraries installed, or they should consult a suitably qualified legal professional to ensure that applications using code from the OpenSSL project are correctly certified for import and export in relevant regions of the world.[/quote]
    You'll need to install OpenSSL separately, then tell your project to link against the the library: http://qt-project.org/forums/viewthread/25799



  • OK, I'll check that out, thanks.

    On a related note, I see that there is a class that can define the proxy settings that can be applied to the application as a whole but it does not seem to have any options for HTTPS (it has HTTP only).

    How would I configure the proxy settings for HTTPS for the application as a whole?



  • Hi,

    I had the same issue with GoogleMaps but using QNetworkRequest. If you request "page":http://maps.google.com Google will redirect you "here":https://maps.google.com I managed to fix this issue using RawHeaders from QNetworkReply.

    Maybe this "thread":http://qt-project.org/forums/viewthread/29760/ will help you.

    Cheers,
    Max.


  • Moderators

    You're welcome, Qu0ll.

    [quote]On a related note, I see that there is a class that can define the proxy settings that can be applied to the application as a whole but it does not seem to have any options for HTTPS (it has HTTP only).

    How would I configure the proxy settings for HTTPS for the application as a whole?[/quote]That's outside my field, sorry -- I don't work with HTTPS much myself. From what I remember though, some of the API is HTTP only.

    You could get better answers about HTTPS configuration from others if you start a new thread. Or even better, ask at the "#qt IRC channel":http://qt-project.org/wiki/OnlineCommunities or the "Interest mailing list":http://lists.qt-project.org/mailman/listinfo/interest -- Qt's engineers are active at those two places.



  • Has anyone actually managed to get Google Maps to display in a WebView? If so, could you please describe what needs to be done to get it to work? My attempts are failing miserably :-(



  • I have it working now. The problem was with the way I installed OpenSSL as discussed in this "thread":http://qt-project.org/forums/viewthread/25799/

    Thanks to everyone who contributed suggestions!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.