Embed YouTube Video in QWebView/ja

From Qt Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine.
Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean.

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

QWebView に YouTube のビデオを埋め込む

この小さなテンプレートでは QWebView に YouTube のビデオを埋め込む方法を説明します。これはまた、Qt で flash をサポートする方法のデモでもあります。 まず、Qt Creator で Qt ウィジェットアプリケーションを作成し、QWebView を追加します。

.pro ファイルの QT 変数に network と webkit を追加します。

QT += core gui network webkit

mainwindow.cpp に以下のコードを追加します。

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"));
}

ビデオが埋め込まれた Web ページが読み込めるようになったはずです。 ローカルの html ファイルに object タグでビデオを埋め込んで、その URL を指定して開くこともできます。

Qt で flash を使う詳細は この記事(英語) を参照してください。