Qt Webkit Tutorial : Web Browser with QtCreator using QWebView - 2020
In this tutorial, we'll make our own browser using Qt Webkit.
First, we'll just try to load a url to display a web page, then start to build the more refined browser.
In my opinion, one of the most important pieces of Qt Webkit is QWebView. The Qt document also says:
QWebView is the main widget component of the QtWebKit web browsing module. It can be used in various applications to display web content live from the Internet.
A web site can be loaded onto QWebView with the load() function. So, the core part of making browser is following lines of code:
QWebView *view = new QWebView(parent); view->load(QUrl("http://google.com/")); view->show();
We make a QWebView object, and load a page using load(). Like all Qt widgets, to display QWebView, the show() function must be invoked.
To make it work, we need a module from webkit (actually, webkitwidgets), and we will set it in .pro file.
Though it's not necessary for this simple project, we'll use Creator.
File->New File or Project...->Other Project->Empty Qt Project->Choose...
Paste the following lines to the Browser1.pro:
QT += core gui QT += webkitwidgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = Browser1 TEMPLATE = app SOURCES += main.cpp
Then we need a main().
Right click on the Project name and select Add new...->C++->C++ Source File->Choose...
Copy the following code for the main.cpp:
#include <QApplication> #include <QWebView> int main(int argc, char *argv[]) { QApplication a(argc, argv); QWebView view; view.show(); view.load(QUrl("http://google.com")); return a.exec(); }
Run qmake->Run, then we'll get our browser with the page loaded:
NOTE: The linking against the Webkit does not seem to be needed. So, I dropped the following line from the Browser1.pro file.
QT += webkit
Though our browser version 1 is able to display a page, it does not have controls such as backward, forward, or refresh etc.
So, in the next tutorial, we'll put some UI elements so that our browser become more closer to the real one.
Qt Webkit Tutorial : Web Browser with QtCreator using QWebView B.
Qt 5 Tutorial
- Hello World
- Signals and Slots
- Q_OBJECT Macro
- MainWindow and Action
- MainWindow and ImageViewer using Designer A
- MainWindow and ImageViewer using Designer B
- Layouts
- Layouts without Designer
- Grid Layouts
- Splitter
- QDir
- QFile (Basic)
- Resource Files (.qrc)
- QComboBox
- QListWidget
- QTreeWidget
- QAction and Icon Resources
- QStatusBar
- QMessageBox
- QTimer
- QList
- QListIterator
- QMutableListIterator
- QLinkedList
- QMap
- QHash
- QStringList
- QTextStream
- QMimeType and QMimeDatabase
- QFile (Serialization I)
- QFile (Serialization II - Class)
- Tool Tips in HTML Style and with Resource Images
- QPainter
- QBrush and QRect
- QPainterPath and QPolygon
- QPen and Cap Style
- QBrush and QGradient
- QPainter and Transformations
- QGraphicsView and QGraphicsScene
- Customizing Items by inheriting QGraphicsItem
- QGraphicsView Animation
- FFmpeg Converter using QProcess
- QProgress Dialog - Modal and Modeless
- QVariant and QMetaType
- QtXML - Writing to a file
- QtXML - QtXML DOM Reading
- QThreads - Introduction
- QThreads - Creating Threads
- Creating QThreads using QtConcurrent
- QThreads - Priority
- QThreads - QMutex
- QThreads - GuiThread
- QtConcurrent QProgressDialog with QFutureWatcher
- QSemaphores - Producer and Consumer
- QThreads - wait()
- MVC - ModelView with QListView and QStringListModel
- MVC - ModelView with QTreeView and QDirModel
- MVC - ModelView with QTreeView and QFileSystemModel
- MVC - ModelView with QTableView and QItemDelegate
- QHttp - Downloading Files
- QNetworkAccessManager and QNetworkRequest - Downloading Files
- Qt's Network Download Example - Reconstructed
- QNetworkAccessManager - Downloading Files with UI and QProgressDialog
- QUdpSocket
- QTcpSocket
- QTcpSocket with Signals and Slots
- QTcpServer - Client and Server
- QTcpServer - Loopback Dialog
- QTcpServer - Client and Server using MultiThreading
- QTcpServer - Client and Server using QThreadPool
- Asynchronous QTcpServer - Client and Server using QThreadPool
- Qt Quick2 QML Animation - A
- Qt Quick2 QML Animation - B
- Short note on Ubuntu Install
- OpenGL with QT5
- Qt5 Webkit : Web Browser with QtCreator using QWebView Part A
- Qt5 Webkit : Web Browser with QtCreator using QWebView Part B
- Video Player with HTML5 QWebView and FFmpeg Converter
- Qt5 Add-in and Visual Studio 2012
- Qt5.3 Installation on Ubuntu 14.04
- Qt5.5 Installation on Ubuntu 14.04
- Short note on deploying to Windows
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization