环境

windows7 + VS2010 + QT5.2_opengl

配置开发环境

1、安装VS2010

2、安装QT 5.2

QT网站:http://qt-project.org/downloads

下载并安装QT5.2:Qt 5.2.1 for Windows 32-bit (VS 2010, OpenGL, 517 MB)

3、安装Visual Studio Add-in for QT5

下载地址:Visual Studio Add-in 1.2.2 for Qt5

4、配置VS 2010

配置路径:QT5 ==> "Qt Options" ==> "Qt Versions" ==> Add

默认路径为:C:\Qt\Qt5.2.0\5.2.0\msvc2010_opengl

解析html

1、建立QtWebkit工程

操作路径:VS2010 ==> File ==> New ==> Project ==> "Qt5 Projects" ==> "Qt Application"

注意事项

在"Project Settings"里面选中“WebKit”和“Webkit Widgets”选项: 

2、添加头文件

#include <QtGui>
#include <QtWebKit>
#include <QWebView>

3、解析内容

3.1、解析http形式的url

使用QWebView的setUrl方法,示例如下:

QWebView view;
view.show();
view.setUrl(QUrl("http://www.cnblogs.com/mikezhang"));

3.2、解析本地文件

使用QWebView的setUrl方法,示例如下:

QWebView view;
view.show();
view.setUrl(QUrl("file:///E:/tmp/1.html"));

3.3、解析html字符串

使用QWebView的setHtml方法,示例如下:

QApplication app(argc, argv);
QWebView view;
view.show();
std::ifstream fin("E:/tmp/1.html");
std::stringstream buffer;
buffer << fin.rdbuf();
fin.close();
view.setHtml(buffer.str().c_str());

完整代码如下

#include <QtGui>
#include <QtWebKit>
#include <QWebView> #include <fstream>
#include <string>
#include <sstream> int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWebView view;
view.show(); // Method 1 : a remote url
//view.setUrl(QUrl("http://www.cnblogs.com/mikezhang")); // Method 2 : a local url
//view.setUrl(QUrl("file:///E:/tmp/1.html")); // Method 3 : set html content
std::ifstream fin("E:/tmp/1.html");
std::stringstream buffer;
buffer << fin.rdbuf();
fin.close();
view.setHtml(buffer.str().c_str()); return app.exec();
}

本文github地址:

https://github.com/mike-zhang/mikeBlogEssays/blob/master/2014/20140205_windows下用QTwebkit解析html.md

欢迎补充

windows下用QTwebkit解析html的更多相关文章

  1. windows下使用xerces -c解析XML

    windows下使用Xerces-C++解析XML 前景提要 最近工作中遇到收到的数据为xml格式的情况,考虑到xml解析应该是个很常用的功能,应该有开源的lib库可以使用,于是就在网上找了找,果然发 ...

  2. Smarty模板Windows下写代码 放到CentOS6.5无法正确解析

    如题:报错: Unable to load template file 'System/header.htm' in '/var/www/website/cms/Template/Default/We ...

  3. 解析 Qt 程序在Windows 下发布

    原文请看:http://www.cnblogs.com/elect-fans/archive/2012/03/15/2408579.html Qt 程序在Windows下发布是本文要介绍的内容,不多说 ...

  4. Linux的.a、.so和.o文件 windows下obj,lib,dll,exe的关系 动态库内存管理 动态链接库搜索顺序 符号解析和绑定 strlen函数的汇编实现分析

    Linux的.a..so和.o文件 - chlele0105的专栏 - CSDN博客 https://blog.csdn.net/chlele0105/article/details/23691147 ...

  5. Windows下解析命令行参数

    linux通常使用GNU C提供的函数getopt.getopt_long.getopt_long_only函数来解析命令行参数. 移植到Windows下 getopt.h #ifndef _GETO ...

  6. Windows下node-gyp查找VS安装路径简单解析

    node-gyp的作用我已经不想赘述了,这里给一个我之前文章的链接:cnblogs看这里,知乎看这里.本文主要从源码入手,介绍node-gyp查找VisualStudio的过程 为了方便我们研究nod ...

  7. Cts框架解析(1)-windows下cts配置

    环境搭建 下载 cts工具的下载地址:http://source.android.com/compatibility/downloads.html windows选择Android4.4 R3 Com ...

  8. Windows下Visual studio 2013 编译 Audacity

    编译的Audacity版本为2.1.2,由于实在windows下编译,其源代码可以从Github上取得 git clone https://github.com/audacity/audacity. ...

  9. Windows下Nginx配置SSL实现Https访问(包含证书生成)

    Vincent.李   Windows下Nginx配置SSL实现Https访问(包含证书生成) Windows下Nginx配置SSL实现Https访问(包含证书生成) 首先要说明为什么要实现https ...

随机推荐

  1. Int,Long比较重使用equal替换==

    首先,==有很多限制,如Integer 类型的值在[-128,127] 期间,Integer 用 “==”是可以的(参考),超过范围则不行,那么使用equal则代替则完全ok public stati ...

  2. ((uchar*)(Img1->imageData + Img1->widthStep*pt.y))[pt.x] 的 具体含义

    widthstep是指图像每行所占的字节数. 主要要和width区别: width是表示图像的每行像素数,widthStep指表示存储一行像素需要的字节数. 在OpenCV里边,widthStep必须 ...

  3. struts2学习笔记--上传单个和批量文件示例

    struts2提供了对上传文件的支持,将上传后的文件封装为java.io.File对象,开发者只需要在Action中定义一个File类型的变量,然后直接使用该变量,将它复制到目的目录即可. 单个文件上 ...

  4. TCP三次握手,四次挥手

    前言 在面试的过程中,TCP的传输协议经常会出现.以前我参加面试的过程中就被问到过,现在轮到我面试其他人的时候,我也会问一些相关的问题.作为一名开发者,无论使用什么样的开发语言,最基本的网络知识一定要 ...

  5. jQuery-1.9.1源码分析系列(十三) 位置大小操作

    先列一下这些个api jQuery.fn.css (propertyName [, value ]| object )(函数用于设置或返回当前jQuery对象所匹配的元素的css样式属性值.如果需要删 ...

  6. jQuery-1.9.1源码分析系列(十四) 一些jQuery工具

    为了给下一章分析动画处理做准备,先来看一下一些工具.其中队列工具在动画处理中被经常使用. jQuery.fn. queue(([ queueName ] [, newQueue ]) || ([ qu ...

  7. Hibernate —— 映射关联关系

    一.映射多对一关联关系. 1.单向的多对一 (1)以 Customer 和 Order 为例:一个用户可以发出多个订单,而一个订单只能属于一个客户.从 Order 到 Customer 是多对一关联关 ...

  8. The Practice of .NET Cross-Platforms

    0x01 Preface This post is mainly to share the technologies on my practice about the .NET Cross-Platf ...

  9. ASP.NET MVC对WebAPI接口操作(添加,更新和删除)

    昨天<怎样操作WebAPI接口(显示数据)>http://www.cnblogs.com/insus/p/5670401.html 既有使用jQuery,也有使作HttpClient来从数 ...

  10. java.net.SocketException: Software caused connection abort: socket write error

    用Java客户端程序访问Java Web服务器时出错: java.net.SocketException: Software caused connection abort: socket write ...