qtwebkit调试google maps的交互问题 (转)

最近在上位机软件加入一个qtwebkit模块,用于加载google maps(V3)。写好google maps的html文件之后,在chrome和IE中显示均正常,但是一旦用qtwebview加载后只能显示基本的地图,鼠标拖动和滚轮放大等交互操作均无法响应,由于原来的google maps html文件调试正常,所以考虑是qtwebview中默认的浏览器引擎造成的原因。

查阅了qtwebview类的用法,发现其中有一个虚函数QString QWebPage::userAgentForUrl ( const QUrl &url ) const,这个一个设置用户代理的函数,重载该函数可以实现更改qtwebview的默认浏览器代理,查阅相关资料后,做如下改动(代码来源:http://stackoverflow.com/questions/6184240/map-doesnt-respond-on-mouse-clicks-with-google-maps-api-v3-and-qwebview):

Add this class in the source file where you are "loading" the HTML file (containing Javascript API) in the Qt widget.

class myWebPage : public QWebPage { virtual QString userAgentForUrl(const QUrl& url) const { return "Chrome/1.0"; } };  

Then in your own class in the same source file, add the setPage function call as shown below and see the magic happen!

MainScreen::MainScreen(QWidget *parent):QWidget(parent) { ... ***map->setPage (new myWebPage());*** map->load (QUrl("./index.html") ) ; };  

即将浏览器代理设置为Chrome版本,继续调试google maps在qtwebview中一切正常。

文章转自:http://blog.csdn.net/jakiechen68/article/details/7710961

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值