私はHTML5を学び、Qtハイブリッドアプリケーションの新機能をテストしています。 ここでは単純なジオロケーションの例を取り上げていますが、navigator.geolocation.getCurrentPosition(displayLocation); QtWebKitはそれをサポートしていないようですが、このhttp://trac.webkit.org/wiki/QtWebKitFeatures22によれば、Qt4.8.0に付属しているQtWebKitのバージョンはジオロケーションをサポートしています。Qt WebKitとHTML5ジオロケーション
これは私が使用しているコードです:
window.onload = function()
{
getMyLocation();
}
function getMyLocation()
{
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(displayLocation);
}
else
{
alert("No geolocation support");
}
}
function displayLocation(position)
{
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var div = document.getElementById("location");
div.innerHTML = "You are at Latitude: " + latitude + ", Longitude: " + longitude;
}
とQt側を:
QWebView* MyWindow::createWebView()
{
QWebSettings* default_settings = QWebSettings::globalSettings();
default_settings->setAttribute(QWebSettings::JavascriptEnabled,true);
default_settings->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled,true);
default_settings->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled,true);
default_settings->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls,true);
default_settings->setAttribute(QWebSettings::LocalStorageEnabled,true);
default_settings->setAttribute(QWebSettings::JavascriptCanAccessClipboard,true);
default_settings->setAttribute(QWebSettings::DeveloperExtrasEnabled,true);
QWebView* web_view = new QWebView(this);
connect(web_view->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
this, SLOT(addJavascriptObject()));
inspector_->setPage(web_view->page());
inspector_->setVisible(true);
inspector_->show();
web_view->load(QUrl("qrc:/html/geolocation_example.html"));
return web_view;
}
誰でもQtのデスクトップアプリのHTML5のジオロケーションを有効にする方法を知っていますか?
問題は、navigator.geolocation.getCurrentPosition(displayLocation);を呼び出さなくても問題がないことです。それはnavigator.geolocation – userX731
userX731を見つけることができません、あなたはこれを理解しましたか? – jdcravens
私はPyQt4を使ってこれを実装しようとしましたが、featurePermissionRequestedシグナルは決して発生しません。 – Snorfalorpagus