[Solved]WebView can't load flash plugin to play swf file
-
hi
I have stuck with this flash problem for days,my environment is
windows 7 64bit,
Qt5.2 32bit,
adobe flash player 11 32bit
and my code is like these:
@
WebView {
id: testWebViewJs
anchors.fill: parent
url: "http://helpx.adobe.com/flash-player.html"experimental.preferences.pluginsEnabled: true; experimental.preferences.javascriptEnabled: true onUrlChanged: { console.log(testWebViewJs.url); } }
@
It display html pages as well,but flash object didn't showed up,it shows a little icon like this:
!http://t1.qpic.cn/mblogpic/92f79b50b83af4f3ecf0/2000.jpg(pic)!
I thought the flash plugin was not loaded,but i don't know why.
any suggestion will be helpful,thanks. -
I checked on Qt5.2 example code "browser" project, and suddenly I finger out the Qt Quick 2 causes this problem,whatever you import QtWebKit.experimental 1.0 and set "experimental.preferences.pluginsEnabled: true", it doesn't work anyway.
So What I need to do is just wrap the QWebView to qml,and it works fine now.
problem resolved. -
[quote author="Gianluca" date="1408976181"]Can you post the code on how to wrap a QWebView to qml ??
I have the same problem, but I don't know how to wrap a QWebView into qml[/quote]You can do it in this way:(from qt 4.8 source code,it's compatible with 4.8/5.3)
@#include "qdeclarativewebview_p.h"#include <QtCore/QDebug>
#include <QtCore/QEvent>
#include <QtCore/QFile>
#include <QtDeclarative/QDeclarativeContext>
#include <QtDeclarative/QDeclarativeEngine>
#include <QtDeclarative/qdeclarative.h>
#include <QtGui/QApplication>
#include <QtGui/QGraphicsSceneMouseEvent>
#include <QtGui/QKeyEvent>
#include <QtGui/QMouseEvent>
#include <QtGui/QPen>
#include "qwebelement.h"
#include "qwebframe.h"
#include "qwebpage.h"
#include "qwebsettings.h"QT_BEGIN_NAMESPACE
class QDeclarativeWebViewPrivate {
public:
QDeclarativeWebViewPrivate(QDeclarativeWebView* qq)
: q(qq)
, preferredwidth(0)
, preferredheight(0)
, progress(1.0)
, status(QDeclarativeWebView::Null)
, pending(PendingNone)
, newWindowComponent(0)
, newWindowParent(0)
, rendering(true)
{
}QDeclarativeWebView* q; QUrl url; // page url might be different if it has not loaded yet GraphicsWebView* view; int preferredwidth, preferredheight; qreal progress; QDeclarativeWebView::Status status; QString statusText; enum { PendingNone, PendingUrl, PendingHtml, PendingContent } pending; QUrl pendingUrl; QString pendingString; QByteArray pendingData; mutable QDeclarativeWebSettings settings; QDeclarativeComponent* newWindowComponent; QDeclarativeItem* newWindowParent; static void windowObjectsAppend(QDeclarativeListProperty<QObject>* prop, QObject* o) { static_cast<QDeclarativeWebViewPrivate*>(prop->data)->windowObjects.append(o); static_cast<QDeclarativeWebViewPrivate*>(prop->data)->updateWindowObjects(); } void updateWindowObjects(); QObjectList windowObjects; bool rendering;
};
void QDeclarativeWebView::init()
{
d = new QDeclarativeWebViewPrivate(this);if (QWebSettings::iconDatabasePath().isNull() && QWebSettings::globalSettings()->localStoragePath().isNull() && QWebSettings::offlineStoragePath().isNull() && QWebSettings::offlineWebApplicationCachePath().isNull()) QWebSettings::enablePersistentStorage(); setAcceptedMouseButtons(Qt::LeftButton); setFlag(QGraphicsItem::ItemHasNoContents, true); setFlag(QGraphicsItem::ItemIsFocusScope, true); setClip(true); d->view = new GraphicsWebView(this); d->view->setResizesToContents(true); d->view->setFocus(); QWebPage* wp = new QDeclarativeWebPage(this); setPage(wp); if (!preferredWidth()) setPreferredWidth(d->view->preferredWidth()); if (!preferredHeight()) setPreferredHeight(d->view->preferredHeight()); connect(d->view, SIGNAL(geometryChanged()), this, SLOT(updateDeclarativeWebViewSize())); connect(d->view, SIGNAL(doubleClick(int, int)), this, SIGNAL(doubleClick(int, int))); connect(d->view, SIGNAL(scaleChanged()), this, SIGNAL(contentsScaleChanged()));
}@
There two file name as you need in qt 4.8 source code:
qdeclarativewebview.cpp
qdeclarativewebview_p.hYou should check on that and build your own wrapper