Environment
Windows7 + VS2010 + Qt5.2_opengl
Configuring the development environment
1. Installation VS2010
2, install QT 5.2
QT Website: http://qt-project.org/downloads
Download and install QT5.2:QT 5.2.1 for Windows 32-bit (VS, OpenGL, 517 MB)
3. Install visual Studio add-in for QT5
Download Address: Visual Studio add-in 1.2.2 for QT5
4, Configuration vs 2010
Configuration path: QT5 ==> "qt Options" ==> "qt versions" ==> ADD
The default path is: C:qtqt5.2.05.2.0msvc2010_opengl
Parsing HTML
1, the establishment of Qtwebkit project
Action path: VS2010 ==> File ==> New ==> Project ==> "Qt5 Projects" ==> "Qt Application"
Attention matters
Select the "WebKit" and "WebKit Widgets" options in "Project Settings":
2. Add header File
#include <QtGui> #include <QtWebKit> #include <QWebView>
3. Content Analysis
3.1, parsing the http form of the URL
Using the Qwebview SetUrl method, the example is as follows:
Qwebview view; View.show (); View.seturl (Qurl ("Http://www.cnblogs.com/mikezhang"));
3.2. Resolve Local Files
Using the Qwebview SetUrl method, the example is as follows:
Qwebview view; View.show (); View.seturl (Qurl ("file:///E:/tmp/1.html"));
3.3. Parse HTML string
Using the Qwebview sethtml method, the example is as follows:
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 ());
The complete code is as follows:
#include <QtGui> #include <QtWebKit> #include <QWebView> #include <fstream> #include < string> #include <sstream> int main (int argc, char *argv[]) { qapplication app (argc, argv); &N Bsp Qwebview view; view.show (); //method 1:a remote URL //view.seturl (Qurl ("Http://www.cnblogs.com/mikezhang")); //method 2:a The 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 (); }