Qt WebKit and HTML5 geolocation | Qt Project forums | Qt Project

Qt WebKit and HTML5 geolocation

 

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:

 

  1. window.onload = function()
  2. {
  3.     getMyLocation();      
  4. }
  5.  
  6. function getMyLocation()
  7. {
  8.     if(navigator.geolocation)
  9.     {
  10.         navigator.geolocation.getCurrentPosition(displayLocation);        
  11.     }  
  12.     else
  13.     {
  14.         alert("No geolocation support");  
  15.     }
  16. }
  17.  
  18. function displayLocation(position)
  19. {
  20.     var latitude = position.coords.latitude;
  21.     var longitude = position.coords.longitude;
  22.    
  23.     var div = document.getElementById("location");
  24.    
  25.     div[removed] = "You are at Latitude: " + latitude + ", Longitude: " + longitude;  
  26. }

 

 

  1. QWebView* MyWindow::createWebView()
  2.     {
  3.         QWebSettings* default_settings = QWebSettings::globalSettings();
  4.         default_settings->setAttribute(QWebSettings::JavascriptEnabled,true);
  5.         default_settings->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled,true);
  6.         default_settings->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled,true);
  7.         default_settings->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls,true);        
  8.         default_settings->setAttribute(QWebSettings::LocalStorageEnabled,true);
  9.         default_settings->setAttribute(QWebSettings::JavascriptCanAccessClipboard,true);
  10.         default_settings->setAttribute(QWebSettings::DeveloperExtrasEnabled,true);
  11.  
  12.         QWebView* web_view = new QWebView(this);
  13.  
  14.         connect(web_view->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
  15.                 this, SLOT(addJavascriptObject()));
  16.  
  17.         inspector_->setPage(web_view->page());
  18.  
  19.         inspector_->setVisible(true);
  20.         inspector_->show();
  21.  
  22.         web_view->load(QUrl("qrc:/html/geolocation_example.html"));
  23.        
  24.         return web_view;
  25.     }

 

Anyone knows how to enable geolocation for a desktop app?

Qt WebKit and HTML5 geolocation | Qt Project forums | Qt Project的更多相关文章

  1. Qt webkit插件相关知识

    1.在Qt中使用 WebKit 浏览器核心 使用 QtWebKit 需要在工程文件(*.pro)中加入: 1.           QT +=webkit   2.           QT += n ...

  2. Qt WebKit 学习的说明

    (转自:http://it.100xuexi.com/view/otdetail/20120827/4021c662-b917-44d9-8284-910cac713c23.html) QT Webk ...

  3. 对Qt for Android的评价(很全面,基本已经没有问题了,网易战网客户端就是Qt quick写的),可以重用QT积累20年的RTL是好事,QML效率是HTML5的5倍

    现在Qt不要光看跨平台了,Qt也有能力和原生应用进行较量的.可以直接去Qt官网查看他和那些厂商合作.关于和Java的比较,框架和Java进行比较似乎不且实际.如果是C++和Java比较,网上有很多文章 ...

  4. Qt webKit可以做什么(四)--实现本地QObject和JavaScript交互

    Qt webKit可以做什么(四)--实现本地QObject和JavaScript交互 Qt webKit可以做什么(四)--实现本地QObject和JavaScript交互

  5. InfoQ访谈:Webkit和HTML5的现状和趋势

    原网址: http://www.infoq.com/cn/interviews/status-and-trends-of-webkit-and-html5 个人一些不成熟的见解,望讨论和指正. 节选 ...

  6. Qt 4.5发布(最大的变动是换用LGPL许可证,移植进了苹果的Cocoa框架。之前的Qt只支持Carbon框架,现在的Qt 4.5两者都支持。单一源代码创建出支持32位或64位字节的Intel或PowerPC Mac二进制文件)

            Nokia的开源Qt开发工具正式发布了4.5版.如前所述,Qt 4.5最大的变动是换用LGPL许可证,目前采用的三个许可证分别为LGPL/GPL和商业许可证.           新版 ...

  7. 【Qt开发】【VS开发】VS2010+Qt开发环境搭建

    QT与JAVA有点类似,也是一种跨平台的软件(当然在windows平台和linux平台需要安装相应的QT开发环境和运行库,类似于JAVA在不同平台下的虚拟机JVM环境),因此对于某些需要同时支持win ...

  8. HTML5 地理位置定位(HTML5 Geolocation)原理及应用

    地理位置(Geolocation)是 HTML5 的重要特性之一,提供了确定用户位置的功能,借助这个特性能够开发基于位置信息的应用.今天这篇文章向大家介绍一下 HTML5 地理位置定位的基本原理及各个 ...

  9. 基于HTML5 geolocation 实现的天气预报功能

    最近一直在学习HTML5,因为8月份要开发手机项目了.所以先把HTML5学习下. 基本思路: 1. 用户未设置任何城市之前,根据HTML5 geolocation 获取用户所在的地理位置. 2. 根据 ...

随机推荐

  1. json中头疼的null

    在服务器返回 json 数据的时候,时常会出现如下数据 "somevalue":null 这个时候,json 解析的时候,就会吧这个 null 解析成 NSNull 的对象,我们向 ...

  2. JS脚本验证大全

    /** * 2009-10-01 * 贺  臣 * 情  缘 * js各种表单数据验证 *//***************************************************** ...

  3. 解决ListView 和ScroolView 共存 listItem.measure(0, 0) 空指针

    在网上找到ListView 和ScroolView 共存的方法无非是给他每个listview 重新增加高度,但是android 的设计者始终认为这并不是一种好的实现方法.但是有的时候有必须要用这种蛋疼 ...

  4. DSP的cache一般在何时会生效,防止在cache使用造成数据不一致

    在使用DSP的cache使能所有的ddr操作时,发现如果只是写操作,根据cache的机制,如果没有在了L1级hit,则直接使用write buffer来完成写操作. 假如hit的话,那之前一定发生过读 ...

  5. JQuery实战学习--在dreamweaver 8中配置Jquery自动提示

    最近在学习jQuery,然后在网上找到了自动提示的方法,记之. 1,首先下载jQuery_API.mxp这个扩展文件. 2,打开DW,点击命令-->扩展管理-->文件-->安装扩展, ...

  6. [转载]Heritrix 提高效率的若干方法

    摘自http://blog.sina.com.cn/s/blog_6cc084c90100nf39.html --------------------------------------------- ...

  7. while和for可以相互转换例子

    //while和for循环可以相互转换,以下为简单格式: ;;) A; 等价于 : ) { A; ; } /* Name:while和for可以相互转换例子 Copyright: By.不懂网络 Au ...

  8. linux系统性能监控常用命令

      一.Linux服务器性能关注点 1)CPU -> load:表示cpu在一段时间内正在处理以及等待处理的任务之和统计信息,简单可理解为cpu正处理的线程数和能同时处理的线程数的比值.一般认为 ...

  9. Changing the Auto-Logout Timeout in SSH

    SSH: We can set a timeout interval for ssh client who are idle or in inactive state. As soon as the ...

  10. zzbank oneOpencloud Env linuxaix6.1 interactiveMaintain(nfs,aix genintall基于系统iso光盘,aix6.1 puppet-Agent,Cent6.4 puppetServer,agent time no syn case Er)

    1,puppet--server,Client,Agent time no syn case eror puppet agent --server frontend -terr: Could not ...