English | Español | Български | 日本語 | Português |

Embed YouTube Video in QWebView

Small snippet showing how to embed a YouTube video in a QWebView [doc.qt.nokia.com]. 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

  1. QT += core gui network webkit

Now add this in your mainwindow.cpp file

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

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 [blog.forwardbias.in]

Categories: