Qt之QtWebKit(一)

 继续研究meego中,不觉2011年的钟声已敲响。新的开始,新的里程。

      今天学习新东西:QtWebKit

      WebKit 是一个开源的浏览器引擎,与之相应的引擎有Gecko(Mozilla Firefox 等使用的排版引擎)和Trident(也称为MSHTML,IE 使用的排版引擎)。同时WebKit 也是苹果Mac OS X 系统引擎框架版本的名称,主要用于Safari,Dashboard,Mail 和其他一些Mac OS X 程序。WebKit 所包含的 WebCore 排版引擎和 JSCore 引擎来自于 KDE 的 KHTML 和 KJS,当年苹果比较了 Gecko 和 KHTML 后,仍然选择了后者,就因为它拥有清晰的源码结构、极快的渲染速度。

      现在浏览器的内核引擎,基本上是三分天下:

  Trident: IE 以Trident 作为内核引擎;

  Gecko: Firefox 是基于 Gecko 开发;

  WebKit: Safari, Google Chrome,搜狗浏览器 基于 Webkit 开发。

    WebKit内核在手机上的应用十分广泛,例如 Google 的手机 Gphone、 Apple 的 iPhone, Nokia’s Series 60 browser 等所使用的 Browser 内核引擎,都是基于 WebKit。

      WebKit从Qt 4.4开始被作为一个Module被集成到Qt中。

      Qt 4.7 使Qt WebKit集成的稳定性和性能均得到提升的更新。

 

      QtWebKit提供了一个web浏览器引擎使World Wide Web更容易集成到Qt应用中. 使web页面能显示各种本地控件,通过JavaScript和本地对象交互.

 

 下面是我写的一个简单的QtWebKit程序。

 

[c-sharp]  view plain copy
  1. ****.pro  
  2. #-------------------------------------------------  
  3. #  
  4. # Project created by QtCreator 2011-01-01T11:44:58  
  5. #  
  6. #-------------------------------------------------  
  7.   
  8. QT       += core gui  
  9. QT       += webkit  
  10.   
  11. TARGET = webkit2  
  12. TEMPLATE = app  
  13.   
  14.   
  15. SOURCES += main.cpp/  
  16.         mainwindow.cpp  
  17.   
  18. HEADERS  += mainwindow.h  
  19.   
  20. OTHER_FILES += /  
  21.     hellowebkit.html /  
  22.     hellowebkit.js /  
  23.     hellowebkit.css  
  24.   
  25. RESOURCES += /  
  26.     resource.qrc  

 

 

[cpp]  view plain copy
  1. //main.cpp  
  2. #include <QtGui/QApplication>  
  3. #include "mainwindow.h"  
  4. #include <QtWebKit/QWebView>  
  5.   
  6. int main(int argc, char *argv[])  
  7. {  
  8.     QApplication a(argc, argv);  
  9.   
  10.     QWebView *view = new QWebView;  
  11.     view->load(QUrl("qrc:/html/hellowebkit.html"));  
  12.     view->show();  
  13.   
  14.     return a.exec();  
  15. }  

 

[xhtml]  view plain copy
  1. //hellowebkit.html  
  2. <html>  
  3.     <head>  
  4.        <meta http-equiv="Content-Type" content="text/html; charset=GB2312" />  
  5.        <title>HelloWorld</title>  
  6.        <mce:script type="text/javascript" src="qrc:/html/hellowebkit.js" mce_src="qrc://writeblog.csdn.net/html/hellowebkit.js"></mce:script>  
  7.        <link rel="stylesheet" href="qrc:/html/hellowebkit.css" mce_href="qrc://writeblog.csdn.net/html/hellowebkit.css" type="text/css"/>  
  8.     </head>  
  9.     <body>  
  10.       <h1>Hello WebKit<h1>  
  11.       <input type="submit" onClick="showMsg()" value="Click Me"/>  
  12.     </body>  
  13. </html>  

 

[css]  view plain copy
  1. //hellowebkit.css  
  2. body {  
  3.     background-color:#99FF00;}  
  4. }  
  5.   
  6. //hellowebkit.js  
  7. function showMsg() {  
  8.     alert("Hello WebKit!");  
  9. }  

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值