Open Web Page in QWebView: Difference between revisions
Jump to navigation
Jump to search
AutoSpider (talk | contribs) (Don't #include the module prefix) |
(Cleanup) |
||
Line 1: | Line 1: | ||
{{ | {{LangSwitch}} | ||
[[Category:Developing_with_Qt::General]] | [[Category:Developing_with_Qt::General]] | ||
[[Category:Developing_with_Qt::QtWebKit]] | [[Category:Developing_with_Qt::QtWebKit]] | ||
Line 6: | Line 5: | ||
[[Category:Snippets]] | [[Category:Snippets]] | ||
[[Category:Tutorial]] | [[Category:Tutorial]] | ||
The following tutorial shows how to load a web page using {{DocLink|QUrl}} in {{DocLink|QWebView}} . QWebView is a widget provided by [http://doc.qt.io/qt-5/qtwebkit-index.html WebKit in Qt] that is used to view and edit web documents. | |||
The following tutorial shows how to load a web page using | |||
* Specify that you want to link against the QtWebkit module by adding this line to your qmake .pro file: | * Specify that you want to link against the QtWebkit module by adding this line to your qmake .pro file: | ||
Line 92: | Line 85: | ||
MainWindow::~MainWindow() | MainWindow::~MainWindow() | ||
{ | { | ||
} | } | ||
</code> | </code> | ||
Line 124: | Line 116: | ||
= See also = | = See also = | ||
[ | [[Embed YouTube Video in QWebView]] |
Revision as of 22:49, 27 June 2015
The following tutorial shows how to load a web page using QUrl in QWebView . QWebView is a widget provided by WebKit in Qt 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
m_pWebView = new QWebView(this);
//set position and size
m_pWebView->setGeometry(0,0,200,200);
Additionally QWebView style can be customized using setStyleSheet().
- Load a web page
m_pWebView->load(QUrl("http://www.example.com"));
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 <QMainWindow>
#include <QWebView>
#include <QUrl>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget '''parent = 0);
virtual ~MainWindow();
private:
QWebView''' m_pWebView;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include <QCoreApplication>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
m_pWebView = new QWebView(this);
//set position and size
m_pWebView->setGeometry(0,0,200,200);
m_pWebView->load(QUrl("http://www.example.com"));
}
MainWindow::~MainWindow()
{
}
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char '''argv[])
{
QApplication app(argc, 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