Open Web Page in QWebView: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
[[Category:Developing_with_Qt::General]]<br />[[Category:Developing_with_Qt::QtWebKit]]<br />[[Category:HowTo]]<br />[[Category:Snippets]]<br />[[Category:Tutorial]] | |||
= | [toc align_right="yes&quot; depth="3&quot;] | ||
'''English''' [[Open_Web_Page_in_QWebView_Bulgarian|Български]] | |||
= Open Web Page in QWebView = | |||
The following tutorial shows how to load a web page using "QUrl&quot;:http://doc.qt.nokia.com/latest/qurl.html in "QWebView&quot;:http://doc.qt.nokia.com/latest/qwebview.html . QWebView is a widget provided by "WebKit in Qt&quot;:http://doc.qt.nokia.com/latest/qtwebkit.html 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: | ||
* | <code><br />QT ''= webkit<br /></code> | ||
** | <br />* Include required headers | ||
* | <br /><code><br />#include <QWebView&gt;<br />#include <QUrl&gt;<br /></code> | ||
<br />* Create instance of QWebView | |||
<br /><code><br />m_pWebView = new QWebView(this);<br />//set position and size<br />m_pWebView->setGeometry(0,0,200,200);<br /></code> | |||
<br />Additionally QWebView style can be customized using '''setStyleSheet()'''. | |||
<br />* Load a web page | |||
<br /><code><br />m_pWebView->load(QUrl("http://www.example.com&quot;));<br /></code> | |||
<br />h2. Example | |||
<br />This example has been built with Qt SDK 1.1 and tested on Symbian^3 devices. | |||
<br />h3. mainwindow.h | |||
<br /><code><br />#ifndef MAINWINDOW_H<br />#define MAINWINDOW_H | |||
<br />#include <QtGui/QMainWindow&gt;<br />#include <QWebView&gt;<br />#include <QUrl&gt; | |||
<br />namespace Ui {<br /> class MainWindow;<br />} | |||
<br />class MainWindow : public QMainWindow<br />{<br /> Q_OBJECT<br />public: | |||
<br /> explicit MainWindow(QWidget '''parent = 0);<br /> virtual ~MainWindow(); | |||
<br />private: | |||
<br /> QWebView''' m_pWebView;<br />}; | |||
<br />#endif // MAINWINDOW_H<br /></code> | |||
<br />h3. mainwindow.cpp | |||
<br /><code><br />#include "mainwindow.h&quot; | |||
<br />#include <QtCore/QCoreApplication&gt; | |||
<br />MainWindow::MainWindow(QWidget *parent)<br /> : QMainWindow(parent)<br />{<br /> m_pWebView = new QWebView(this);<br /> //set position and size<br /> m_pWebView->setGeometry(0,0,200,200);<br /> m_pWebView->load(QUrl("http://www.example.com&quot;));<br />} | |||
<br />MainWindow::~MainWindow()<br />{ | |||
<br />}<br /></code> | |||
<br />h3. main.cpp | |||
<br /><code><br />#include "mainwindow.h&quot; | |||
<br />#include <QtGui/QApplication&gt; | |||
<br />int main(int argc, char '''argv[])<br />{<br /> QApplication app(argc, argv); | |||
<br /> MainWindow mainWindow;<br /> mainWindow.showMaximized();<br /> return app.exec&amp;#40;&#41;;<br />} | |||
<br /></code> | |||
<br />h2. Troubleshooting | |||
<br />''' '''QWebView: No such file or directory''' | |||
<br />Make sure you have added '''webkit''' to the .pro file of the project. | |||
<br /><code><br />QT''= webkit<br /></code> | |||
= See also = | |||
"Embed YouTube Video in QWebView&quot;:http://developer.qt.nokia.com/wiki/Embed_YouTube_Video_in_QWebView | |||
Revision as of 14:32, 23 February 2015
[toc align_right="yes" depth="3"]
English Български
Open Web Page in QWebView
The following tutorial shows how to load a web page using "QUrl":http://doc.qt.nokia.com/latest/qurl.html in "QWebView":http://doc.qt.nokia.com/latest/qwebview.html . QWebView is a widget provided by "WebKit in Qt":http://doc.qt.nokia.com/latest/qtwebkit.html 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:
<br />QT ''= webkit<br />
* Include required headers
<br />#include <QWebView&gt;<br />#include <QUrl&gt;<br />
* Create instance of QWebView
<br />m_pWebView = new QWebView(this);<br />//set position and size<br />m_pWebView->setGeometry(0,0,200,200);<br />
Additionally QWebView style can be customized using setStyleSheet().
* Load a web page
<br />m_pWebView->load(QUrl("http://www.example.com&quot;));<br />
h2. Example
This example has been built with Qt SDK 1.1 and tested on Symbian^3 devices.
h3. mainwindow.h
<br />#ifndef MAINWINDOW_H<br />#define MAINWINDOW_H
<br />#include <QtGui/QMainWindow&gt;<br />#include <QWebView&gt;<br />#include <QUrl&gt;
<br />namespace Ui {<br /> class MainWindow;<br />}
<br />class MainWindow : public QMainWindow<br />{<br /> Q_OBJECT<br />public:
<br /> explicit MainWindow(QWidget '''parent = 0);<br /> virtual ~MainWindow();
<br />private:
<br /> QWebView''' m_pWebView;<br />};
<br />#endif // MAINWINDOW_H<br />
h3. mainwindow.cpp
<br />#include "mainwindow.h&quot;
<br />#include <QtCore/QCoreApplication&gt;
<br />MainWindow::MainWindow(QWidget *parent)<br /> : QMainWindow(parent)<br />{<br /> m_pWebView = new QWebView(this);<br /> //set position and size<br /> m_pWebView->setGeometry(0,0,200,200);<br /> m_pWebView->load(QUrl("http://www.example.com&quot;));<br />}
<br />MainWindow::~MainWindow()<br />{
<br />}<br />
h3. main.cpp
<br />#include "mainwindow.h&quot;
<br />#include <QtGui/QApplication&gt;
<br />int main(int argc, char '''argv[])<br />{<br /> QApplication app(argc, argv);
<br /> MainWindow mainWindow;<br /> mainWindow.showMaximized();<br /> return app.exec&amp;#40;&#41;;<br />}
<br />
h2. Troubleshooting
QWebView: No such file or directory
Make sure you have added webkit to the .pro file of the project.
<br />QT''= webkit<br />
See also
"Embed YouTube Video in QWebView":http://developer.qt.nokia.com/wiki/Embed_YouTube_Video_in_QWebView