Open Web Page in QWebView: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
'''English''' [[Open Web Page in QWebView Bulgarian|Български]]
[[Category:Developing_with_Qt::General]]<br />[[Category:Developing_with_Qt::QtWebKit]]<br />[[Category:HowTo]]<br />[[Category:Snippets]]<br />[[Category:Tutorial]]


=Open Web Page in QWebView=
[toc align_right=&quot;yes&amp;quot; depth=&quot;3&amp;quot;]


The following tutorial shows how to load a web page using [http://doc.qt.nokia.com/latest/qurl.html QUrl] ''[doc.qt.nokia.com]'' in [http://doc.qt.nokia.com/latest/qwebview.html QWebView] ''[doc.qt.nokia.com]'' . QWebView is a widget provided by [http://doc.qt.nokia.com/latest/qtwebkit.html WebKit in Qt] ''[doc.qt.nokia.com]'' that is used to view and edit web documents.
'''English''' [[Open_Web_Page_in_QWebView_Bulgarian|Български]]


* Specify that you want to link against the QtWebkit module by adding this line to your qmake .pro file:
= Open Web Page in QWebView =


* Include required headers
The following tutorial shows how to load a web page using &quot;QUrl&amp;quot;:http://doc.qt.nokia.com/latest/qurl.html in &quot;QWebView&amp;quot;:http://doc.qt.nokia.com/latest/qwebview.html . QWebView is a widget provided by &quot;WebKit in Qt&amp;quot;:http://doc.qt.nokia.com/latest/qtwebkit.html that is used to view and edit web documents.


* Create instance of QWebView
* Specify that you want to link against the QtWebkit module by adding this line to your qmake .pro file:
 
Additionally QWebView style can be customized using '''setStyleSheet()'''.
 
* Load a web page
 
==Example==
 
This example has been built with Qt <span class="caps">SDK</span> 1.1 and tested on Symbian^3 devices.
 
===mainwindow.h===
 
===mainwindow.cpp===
 
===main.cpp===
 
==Troubleshooting==
 
* '''QWebView: No such file or directory'''
 
Make sure you have added '''webkit''' to the .pro file of the project.
 
=See also=
 
[http://developer.qt.nokia.com/wiki/Embed_YouTube_Video_in_QWebView Embed YouTube Video in QWebView] ''[developer.qt.nokia.com]''<br />[http://developer.qt.nokia.com/wiki/Extending_QtWebKit Extending QtWebKit] ''[developer.qt.nokia.com]''
 
===Categories:===


* [[:Category:Developing with Qt|Developing_with_Qt]]
<code><br />QT ''= webkit<br /></code>
** [[:Category:Developing with Qt::General|General]]
<br />* Include required headers
* [[:Category:Developing with Qt::QtWebKit|QtWebKit]]
<br /><code><br />#include &lt;QWebView&amp;gt;<br />#include &lt;QUrl&amp;gt;<br /></code>
<br />* Create instance of QWebView
<br /><code><br />m_pWebView = new QWebView(this);<br />//set position and size<br />m_pWebView-&gt;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-&gt;load(QUrl(&quot;http://www.example.com&amp;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 &lt;QtGui/QMainWindow&amp;gt;<br />#include &lt;QWebView&amp;gt;<br />#include &lt;QUrl&amp;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 &quot;mainwindow.h&amp;quot;
<br />#include &lt;QtCore/QCoreApplication&amp;gt;
<br />MainWindow::MainWindow(QWidget *parent)<br /> : QMainWindow(parent)<br />{<br /> m_pWebView = new QWebView(this);<br /> //set position and size<br /> m_pWebView-&gt;setGeometry(0,0,200,200);<br /> m_pWebView-&gt;load(QUrl(&quot;http://www.example.com&amp;quot;));<br />}
<br />MainWindow::~MainWindow()<br />{
<br />}<br /></code>
<br />h3. main.cpp
<br /><code><br />#include &quot;mainwindow.h&amp;quot;
<br />#include &lt;QtGui/QApplication&amp;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;amp;#40;&amp;#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>


* [[:Category:Developing with Qt::Qt Quick::Tutorial|Tutorial]]
= See also =


* [[:Category:HowTo|HowTo]]
&quot;Embed YouTube Video in QWebView&amp;quot;:http://developer.qt.nokia.com/wiki/Embed_YouTube_Video_in_QWebView
* [[:Category:snippets|snippets]]

Revision as of 14:32, 23 February 2015





[toc align_right="yes&quot; depth="3&quot;]

English Български

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:
<br />QT ''= webkit<br />


* Include required headers


<br />#include &lt;QWebView&amp;gt;<br />#include &lt;QUrl&amp;gt;<br />


* Create instance of QWebView


<br />m_pWebView = new QWebView(this);<br />//set position and size<br />m_pWebView-&gt;setGeometry(0,0,200,200);<br />


Additionally QWebView style can be customized using setStyleSheet().
* Load a web page


<br />m_pWebView-&gt;load(QUrl(&quot;http://www.example.com&amp;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 &lt;QtGui/QMainWindow&amp;gt;<br />#include &lt;QWebView&amp;gt;<br />#include &lt;QUrl&amp;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 &quot;mainwindow.h&amp;quot;
<br />#include &lt;QtCore/QCoreApplication&amp;gt;
<br />MainWindow::MainWindow(QWidget *parent)<br /> : QMainWindow(parent)<br />{<br /> m_pWebView = new QWebView(this);<br /> //set position and size<br /> m_pWebView-&gt;setGeometry(0,0,200,200);<br /> m_pWebView-&gt;load(QUrl(&quot;http://www.example.com&amp;quot;));<br />}
<br />MainWindow::~MainWindow()<br />{
<br />}<br />


h3. main.cpp


<br />#include &quot;mainwindow.h&amp;quot;
<br />#include &lt;QtGui/QApplication&amp;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;amp;#40;&amp;#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&quot;:http://developer.qt.nokia.com/wiki/Embed_YouTube_Video_in_QWebView