QtWebEngine location access

  • Is there some trick to enabling location access for a webapp using the QtWebEngine?

    I'm just experimenting, using Sailbook as a template, with using google maps urls. The page loads and looks good but it simply doesn't have location access; there is no prompt from the webengine or OS, and the webpage just says it cannot determine location.

    I've adjusted the apparmor settings and added QtLocation and QtPositioning imports to the qml files. However all I can find is tutorials for using the mapping features of Qt and none that speak to finding current location.

    Anyone know of a tutorial or the right documentation?

  • Is the code not using Morph.Web API to embed the engine? Although I think QtWebEngine itself should already be using the proper API for asking location access from Qt. Otherwise it may just be that you're missing the extra dialog implementation if you're embedding QtWebEngine itself instead of Morph.Web.

    I don't think you should need to use QtLocation or QtPositioning at all yourself, for a web page to get it. As long as the apparmor json is correct, it should work (and remember, if you change the apparmor, you need to change the version so the profile gets rebuilt when installing the app).

  • @dobey
    I didn't know about the version thing thx. However that's not the trouble it seems. Perhaps I should find a clean template to work from.

  • Looking closer there is no embedded webengine just imports in main.qml. But it does do:

    import Morph.Web 0.1
    import QtWebEngine 1.7

    so I have to admit I don't really know what is going on, I'm going to look for a clean template.

  • @dobey you were correct, the location call was just being ignored. Adding the necessary lines enabled access for the webapp. Thanks for the direction.

    I copied this from the Morph browser code:

    onFeaturePermissionRequested: {
        switch(feature) {
            case WebEngineView.Geolocation:
            grantFeaturePermission(securityOrigin, feature, true);

    there is of course cases for other feature requests in the code I copied, and this just grants permission passing responsibility for approving the call to the OS. This does work around the issue where Morph asks permission each and everytime location is called, without the trouble of approving different sites as there is only one.

Log in to reply