createWindow函数不加载flashplayer内容

时间:2014-11-13 18:09:57

标签: c++ qt flash qwebview

我目前正在尝试开发一个基本的浏览器网站,以便使用qt框架在特定的互联网网站上冲浪。我创建了一个继承QWebView并重新实现createWindow函数的MyWindow类,以便在新的浏览器窗口中处理潜在弹出窗口的打开。 它在“正常”导航期间运行良好,但是当我遇到如下链接时:

<a class="lien_default" href="javascript:popupChat2('foo.php?id=42250')">bar</a>

如果链接页面有Flash内容,则会创建一个新窗口,但它是空的。这是popupChat2的代码:

function popupChat2(page)
{fenetre=window.open(page,'chat','top=0, left=0, width=800, height=500, resizable=no, toolbar=no, scrollbars=no, status=no, menubar=no, titlebar=no, dependent=yes');}

我还尝试保存本地链接页面,如果我用一个非常简单的qt浏览器网页打开它,就像这样:

的main.cpp

#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
   QApplication a(argc, argv);
   MainWindow w;
   w.show();

   return a.exec();
}

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
   QMainWindow(parent),
   ui(new Ui::MainWindow)
{
   QUrl url("file:///[url of the page locally saved with flash player content]");
   ui->setupUi(this);
   QWebSettings *settings = ui->webView->settings();
   settings->setAttribute(QWebSettings::JavascriptEnabled, true);
   settings->setAttribute(QWebSettings::PluginsEnabled, true);
   settings->setAttribute(QWebSettings::AutoLoadImages, true);
   settings->setAttribute(QWebSettings::JavaEnabled, false);
   settings->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
   settings->setAttribute(QWebSettings::LocalContentCanAccessFileUrls,true);

   ui->webView->load(url);
   ui->webView->show();
}

MainWindow::~MainWindow()
{
   delete ui;
}

正确加载。 以下是我的createWindow函数的代码和带有flash内容的链接页面的代码:

MyWindow *MyWindow::createWindow(QWebPage::WebWindowType type)
      {
        Q_UNUSED(type);
        MyWindow *webView = new MyWindow;

        webView->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
        webView->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
        webView->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
        webView->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);

        webView->setAttribute(Qt::WA_DeleteOnClose, true);

        QWebPage *newWeb = new QWebPage(webView);
        newWeb->setNetworkAccessManager(page()->networkAccessManager());

        webView->setPage(newWeb);
        webView->show();

        return webView;
    }

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Taverna dei d'Alcontres</title></head>

<script language="Javascript">
function popUpPerso(page)
{
        fenetre = window.open(page, 'perso', 'top=0, left=0, width=650, height=638, resizable=0, toolbar=0, scrollbars=0, status=0, menubar=0, titlebar=0, location=0, dependent=yes');
}

function popUpMains()
{
   fenetre = window.open('/EcranPrincipal.php?l=34&action=14', 'main');
}

function closeWindow()
{
   window.close();
}

function flashTheWindow()
{
   window.GetAttention();
}
</script>

<body bgcolor="#ffffff" style="margin:0;">
<script type="text/javascript">
<!--
function format(val) {
   sign = val < 0 ? "-":"";
   rval = Math.abs(Math.round(val*100));
   str = rval.toString();
   if(rval < 10) str = "0.0"+str;
   else if(rval < 100) str = "0."+str;
   else str = str.substring(0, str.length-2)
     + "." + str.substring(str.length-2, str.length);
   return sign+str;
}

var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the FSCommand messages in a Flash movie.

function Taverne_DoFSCommand(command, args) {
   var TaverneObj = isInternetExplorer ? document.all.Taverne : document.Taverne;
   if (command == "closeWindow") {
       closeWindow();
   }
   if (command == "flashWindow") {
       flashTheWindow();
   }
}
// Hook for Internet Explorer.
   if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
    document.write('<script language="VBScript">\n');
    document.write('On Error Resume Next\n');
    document.write('Sub Taverne_FSCommand(ByVal command, ByVal args)\n');
    document.write('    Call Taverne_DoFSCommand(command, args)\n');
    document.write('End Sub\n');
    document.write('</script\>\n');
}
//-->
</script>

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"     codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="1200" height="700" id="Taverne" align="middle">
<param name="allowScriptAccess" value="always" />
<param name="movie" value="http://d2wb3jk3zoe588.cloudfront.net/divers/taverne5.swf?myTaverne=41785&myLogin=sir_marcus&myPassword=a5c358a794d018f6737ecf76cab2c31f&estNoble=0&estTavernier=0&SonEnTaverne=1&html_address=ns36946.ovh.net&html_port=8080&codeLangue=it&nbPlacesTiersEtat=8&nbPlacesNoblesse=1&NomTaverne=Taverna+dei+d%27Alcontres&nbPlacesPersonnelTaverne=1&doitParlerDansTaverne=0&doitOffrirABoireDansTaverne=0&doitMangerDansTaverne=0&typeEtablissement=0&mainsRestantes=10&version=3.0" />
<param name="quality" value="high" />
<param name="bgcolor" value="#000000" />
<param name="menu" value="false" />
<embed src="http://d2wb3jk3zoe588.cloudfront.net/divers/taverne5.swf?myTaverne=41785&myLogin=sir_marcus&myPassword=a5c358a794d018f6737ecf76cab2c31f&estNoble=0&estTavernier=0&SonEnTaverne=1&html_address=ns36946.ovh.net&html_port=8080&codeLangue=it&nbPlacesTiersEtat=8&nbPlacesNoblesse=1&NomTaverne=Taverna+dei+d%27Alcontres&nbPlacesPersonnelTaverne=1&doitParlerDansTaverne=0&doitOffrirABoireDansTaverne=0&doitMangerDansTaverne=0&typeEtablissement=0&mainsRestantes=10&version=3.0" quality="high" bgcolor="#000000" menu="false" width="1200" height="700" name="Taverne" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</body>
</html>

谢谢

Hicarus

1 个答案:

答案 0 :(得分:0)

您在webView上应用QWebSettings,但它们实际存储在webView->page()中。

所以当你执行webView->setPage(newWeb);时,你会恢复默认的QWebSettings,包括所需的QWebSettings :: PluginsEnabled。

事实上,您似乎不需要额外的QWebPage,只需将您的QNAM设置为默认值:

webView->page()->setNetworkAccessManager(page()->networkAccessManager());