Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. Qt WebKit and HTML5 geolocation
Forum Update on Monday, May 27th 2025

Qt WebKit and HTML5 geolocation

Scheduled Pinned Locked Moved Qt WebKit
1 Posts 1 Posters 3.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mugen731
    wrote on 25 Mar 2012, 00:00 last edited by
    #1

    I'm learning HTML5 and testing the new features on a Qt hybrid application.
    Now I'm working on a simple geolocation example but when I call navigator.geolocation.getCurrentPosition(displayLocation); it seems the QtWebKit does not support it, but acording to this http://trac.webkit.org/wiki/QtWebKitFeatures22 the version of QtWebKit that comes with Qt4.8.0 supports geolocation.

    This is the code I'm using:

    @
    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[removed] = "You are at Latitude: " + latitude + ", Longitude: " + longitude;   
    

    }
    @

    @
    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;
    }
    

    @

    Anyone knows how to enable geolocation for a desktop app?

    1 Reply Last reply
    1

    1/1

    25 Mar 2012, 00:00

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved