Table of Content
English Български
Open Web Page in QWebView
The following tutorial shows how to load a web page using QUrl [doc.qt.nokia.com] in QWebView [doc.qt.nokia.com] . QWebView is a widget provided by WebKit in Qt [doc.qt.nokia.com] that is used to view and edit web documents.
- Specify that you want to link against the QtWebkit module by adding this line to your qmake .pro file:
- QT += webkit
- Include required headers
- #include <QWebView>
- #include <QUrl>
- Create instance of QWebView
- //set position and size
- m_pWebView->setGeometry(0,0,200,200);
Additionally QWebView style can be customized using setStyleSheet().
- Load a web page
Example
This example has been built with Qt SDK 1.1 and tested on Symbian^3 devices.
mainwindow.h
- #ifndef MAINWINDOW_H
- #define MAINWINDOW_H
- #include <QtGui/QMainWindow>
- #include <QWebView>
- #include <QUrl>
- namespace Ui {
- class MainWindow;
- }
- {
- Q_OBJECT
- public:
- virtual ~MainWindow();
- private:
- };
- #endif // MAINWINDOW_H
mainwindow.cpp
- #include "mainwindow.h"
- #include <QtCore/QCoreApplication>
- {
- //set position and size
- m_pWebView->setGeometry(0,0,200,200);
- }
- MainWindow::~MainWindow()
- {
- }
main.cpp
- #include "mainwindow.h"
- #include <QtGui/QApplication>
- int main(int argc, char *argv[])
- {
- MainWindow mainWindow;
- mainWindow.showMaximized();
- return app.exec();
- }
Troubleshooting
- QWebView: No such file or directory
Make sure you have added webkit to the .pro file of the project.
- QT += webkit
See also
Embed YouTube Video in QWebView [developer.qt.nokia.com]
Extending QtWebKit [developer.qt.nokia.com]

