Embed YouTube Video in QWebView: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(Convert ExpressionEngine links)
(Cleanup)
 
Line 1: Line 1:
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}
{{LangSwitch}}
 
'''English''' | [[Embed_YouTube_Video_in_QWebView_German|Deutsch]] | [[Embed_YouTube_Video_in_QWebView_Spanish|Español]] | [[Embed_YouTube_Video_in_QWebView_Bulgarian|Български]] | [[Embed_YouTube_Video_in_QWebView_Japanese|日本語]] | [[Embed_YouTube_Video_in_QWebView_Portuguese|Português]] |
 
[[Category:snippets]]
[[Category:snippets]]
[[Category:Developing_with_Qt::QtWebKit]]
[[Category:Developing_with_Qt::QtWebKit]]
 
Small snippet showing how to embed a YouTube video in a {{DocLink|QWebView}}. This also demonstrates Qt support for flash. First create a Qt Gui Application using Qt Creator and add a QWebView to it.
= Embed YouTube Video in QWebView =
 
Small snippet showing how to embed a YouTube video in a [http://doc.qt.io/qt-5.0/qtwebkit/qwebview.html QWebView]. This also demonstrates Qt support for flash.
First create a Qt Gui Application using Qt Creator and add a QWebView to it.


Now add network and webkit support to your .pro file
Now add network and webkit support to your .pro file
Line 18: Line 11:
Now add this in your mainwindow.cpp file
Now add this in your mainwindow.cpp file
<code>
<code>
MainWindow::MainWindow(QWidget *parent) :
MainWindow::MainWindow(QWidget *parent)  
QMainWindow(parent),
    : QMainWindow(parent)
ui(new Ui::MainWindow)
    , ui(new Ui::MainWindow)
{
{
ui->setupUi(this);
    ui->setupUi(this);
QNetworkProxyFactory::setUseSystemConfiguration (true);
    QNetworkProxyFactory::setUseSystemConfiguration(true);
QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true);
    QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true);
QWebSettings::globalSettings()->setAttribute(QWebSettings::AutoLoadImages, true);
    QWebSettings::globalSettings()->setAttribute(QWebSettings::AutoLoadImages, true);
ui->webView->load(QUrl("http://www.youtube.com/watch?v=3aR27FLbb04"));
    ui->webView->load(QUrl("http://www.youtube.com/watch?v=3aR27FLbb04"));
}
}
</code>
</code>

Latest revision as of 17:35, 28 June 2015

En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh

Small snippet showing how to embed a YouTube video in a QWebView. This also demonstrates Qt support for flash. First create a Qt Gui Application using Qt Creator and add a QWebView to it.

Now add network and webkit support to your .pro file

QT += core gui network webkit

Now add this in your mainwindow.cpp file

MainWindow::MainWindow(QWidget *parent) 
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QNetworkProxyFactory::setUseSystemConfiguration(true);
    QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true);
    QWebSettings::globalSettings()->setAttribute(QWebSettings::AutoLoadImages, true);
    ui->webView->load(QUrl("http://www.youtube.com/watch?v=3aR27FLbb04"));
}

You should be able to load the webpage with the embedded video in it. You could also embed this video only in an object tag in a local html file and just point the url to this local file.

Detailed article on using flash with Qt can be found here