2
It is possible to use Geolocation API with desktop applications using QWebView
?
- I tried to Qty Webkit and HTML5 Geolocation, but it doesn’t work.
- I tried to it’s the Qt5 position api support for desktop app(like mac or windows), but this answer is about the Qt Apis, I want to know if it is not possible on the Desktops then it is perhaps possible to customize the "event" as it is done with
qwebkitplatformplugin
which is used to customize some features inqtwebkit
(Multipleselections, Notifications, Haptics, Touchinteraction, Fullscreenvideoplayer and Spellchecker).
I tried to use PermissionGrantedByUser
, but it doesn’t work:
void WebPage::permissionRequested(QWebFrame* frame, Feature feature)
{
switch (feature) {
case Geolocation:
qDebug() << "GEO-Location: PermissionGrantedByUser";
setFeaturePermission(frame, feature, PermissionGrantedByUser);
break;
default:
qDebug() << "";
}
}
- I tried to
QT += positioning
, but it doesn’t work - I tried to
TARGET.CAPABILITY += NetworkServices Location
, but it doesn’t work. I believe this flag whether for smartphones, such as Symbian.
The events displayLocation
and watchPosition
are never fired and used { timeout: ... }
will show Timeout expired
after the specified time:
<script>
function displayError(err) {
document.getElementById("geo").innerHTML = ("Código de erro: " + err.code +
" / mensagem: " + err.message);
}
function displayLocation(position) {
document.getElementById("geo").innerHTML = [
"latitude:" + position.coords.latitude,
"longitude:" + position.coords.longitude
].join(", ");
}
function getMyLocation() {
if (navigator.geolocation) {
navigator.geolocation.watchPosition(function(a, b, c) {
console.log(a, b, c);
document.getElementById("geo").innerHTML = "Testando...";
});
navigator.geolocation.getCurrentPosition(displayLocation, displayError, {
enableHighAccuracy: false,
timeout: 1000,
maximumAge: 0
});
} else {
document.getElementById("geo").innerHTML = "Geo-Localização não suportado";
}
}
window.onload = function() {
getMyLocation();
};
</script>
<div id="geo"></div>
I believe I have to create a plugin with Qt and put in the folder qtDir/compiler/plugins/position
, but I don’t know where to start creating this plugin.
How can I do this?
You can customize events and send simulated coordinates or by a third-party library (I’m not asking for a library or Javascript alternatives) to the navigator.geolocation.getCurrentPosition
?
Extra information
Use QT_DEBUG_PLUGINS=1
in the purification mode (debug mode
) the Application Output returns this (note that the first line of log 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" ...
In other words, when I run Javascript navigator.geolocation
the Qt calls the C:/Qt5.4.0/5.4/mingw491_32/plugins/position/qtposition_positionpoll.dll
, but does not return any information back to the QWebView
.