QWebView and geolocation.getCurrentPosition?



  • It is possible to use geolocation in Desktop applications with QWebView?

    I tried set PermissionGrantedByUser, but not work:

    void WebPage::permissionRequested(QWebFrame* frame, QWebPage::Feature feature)
    {
        setFeaturePermission(frame, feature, PermissionGrantedByUser);
    }
    
    • I tried add this QT += positioning, but not work
    • I tried add this TARGET.CAPABILITY += NetworkServices Location, but not work, I believe this is for smartphones, like symbian.

    Event displayLocation is never fired:

    <script>
    function getMyLocation() {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(displayLocation);
        } else {
            alert("No geolocation support");
        }
    }
    
    function displayLocation(position) {
        document.getElementById("geo").innerHTML = [
            "latitude:" + position.coords.latitude,
            "longitude:" + position.coords.longitude
        ].join(", ");
    }
    
    window.onload = function() {
        getMyLocation();
    };
    </script>
    <div id="geo"></div>
    

    I believe that I have to build a library and put in the qtDir/compiler/plugins/geoservices, but do not know where to start or if I have to use lib qtgeoservices_nokia or qtgeoservices_osm

    How can I do this?

    Or is it possible to customize the event and send coordinates of a 3rdparty lib (I'm not asking for a library and I'm not asking for alternatives in javascript) in response to the navigator.geolocation.getCurrentPosition?


    Extra info about

    If use QT_DEBUG_PLUGINS=1 in debug mode Application Output return this (note that the first line is generated by WebPage::permissionRequested):

    GEO-Location: PermissionGrantedByUser
    QFactoryLoader::QFactoryLoader() checking directory path "C:/Qt5.4.0/5.4/mingw491_32/plugins/position" ...
    QFactoryLoader::QFactoryLoader() looking at "C:/Qt5.4.0/5.4/mingw491_32/plugins/position/qtposition_positionpoll.dll"
    Found metadata in lib C:/Qt5.4.0/5.4/mingw491_32/plugins/position/qtposition_positionpoll.dll, metadata=
    {
        "IID": "org.qt-project.qt.position.sourcefactory/5.0",
        "MetaData": {
            "Keys": [
                "positionpoll"
            ],
            "Monitor": true,
            "Position": false,
            "Priority": 1000,
            "Provider": "positionpoll",
            "Satellite": false
        },
        "className": "QGeoPositionInfoSourceFactoryPoll",
        "debug": false,
        "version": 328704
    }
    
    
    "The plugin 'C:/Qt5.4.0/5.4/mingw491_32/plugins/position/qtposition_positionpoll.dll' uses incompatible Qt library. (Cannot mix debug and release libraries.)"
             not a plugin
    QFactoryLoader::QFactoryLoader() looking at "C:/Qt5.4.0/5.4/mingw491_32/plugins/position/qtposition_positionpolld.dll"
    Found metadata in lib C:/Qt5.4.0/5.4/mingw491_32/plugins/position/qtposition_positionpolld.dll, metadata=
    {
        "IID": "org.qt-project.qt.position.sourcefactory/5.0",
        "MetaData": {
            "Keys": [
                "positionpoll"
            ],
            "Monitor": true,
            "Position": false,
            "Priority": 1000,
            "Provider": "positionpoll",
            "Satellite": false
        },
        "className": "QGeoPositionInfoSourceFactoryPoll",
        "debug": true,
        "version": 328704
    }
    
    
    Got keys from plugin meta data ("positionpoll")
    QFactoryLoader::QFactoryLoader() checking directory path "C:/projects/webview-example/debug/position" ...


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