• 10756阅读
  • 5回复

QWebView,无法解析某些JS ???????? [复制链接]

上一主题 下一主题
离线nikshuang2
 
只看楼主 倒序阅读 楼主  发表于: 2009-07-31
— 本帖被 XChinux 从 General Qt Programming 移动到本区(2011-01-02) —
    RT,我写了个程序,用QWebView来load一个调用了一些JS的时钟网页。这个网页用firefox是可以看到正常的时钟效果,但用我写的这个程序调用网页,时钟没有动起来,感觉是部分JS函数没有能被解析执行。这个时钟程序不知道是否是用标准的JS编写,firefox能用,我姑且认为他是标准的JS,但为什么用QWebView就不能正常显示它呢,难道不是标准JS编写的??

    时钟程序的部分代码如下,请高手帮忙看下:

index.html:

<!DOCTYPE html>

<html>

<head>

<base href=".">

<script type="text/javascript">if(parent.emulator)parent.emulator.begin(window);</script>

<title>Clock</title>

<link rel="stylesheet" type="text/css" href="style.css">

<link rel="stylesheet" type="text/css" href="skins.css">

<script type="text/javascript" src="js/config.js"></script>

<script type="text/javascript" src="js/widgetModes.js"></script>

<script type="text/javascript" src="js/wdgtclock.js"></script>

</head>

<body>

  <div id="dock"></div>

  <div id="mainview" class="white">

    <canvas width="187" height="186" id="playfield"></canvas>

    <img id="gloss" src="" width="161" height="159">

    <img id="dot" src="" width="20" height="20">

    <p id="date"></p>

    <div id="hands">

      <div id="hours"></div>

      <div id="minutes"></div>

      <div id="seconds"></div>

    </div>

  </div>

</body>

</html>


js/wdgtclock.js
var ctx

    ,old_s_a = 0;


window.addEventListener("load",function(ev)

{

  if (navigator.platform.toLowerCase().indexOf('linux') > -1 ) { document.body.className = "linux" };

  ctx = document.getElementById("playfield").getContext("2d");

  var d = document.getElementById('mainview');

  d.className = config.SKINS[skinCounter];

  var dock = document.getElementById("dock");

  configure();

  clock();

}

,false);



function configure()

{

  var hour_css = window.getComputedStyle(document.getElementById("hours"),null)

      ,min_css = window.getComputedStyle(document.getElementById("minutes"),null)

      ,sec_css = window.getComputedStyle(document.getElementById("seconds"),null);



  config.HAS_SHADOW    = (hour_css.getPropertyValue("padding-top") != "none")?true:false;

  config.HOUR_LENGTH  = parseInt(hour_css.getPropertyValue("height"));

  config.HOUR_WIDTH   = parseInt(hour_css.getPropertyValue("width"));

  config.HOUR_OFFSET  = h_off = -parseInt(hour_css.getPropertyValue("margin-top"));



  config.MIN_LENGTH   = parseInt(min_css.getPropertyValue("height"));

  config.MIN_WIDTH    = parseInt(min_css.getPropertyValue("width"));

  config.MIN_OFFSET   = -parseInt(min_css.getPropertyValue("margin-top"));



  config.SEC_LENGTH   = parseInt(sec_css.getPropertyValue("height"));

  config.SEC_WIDTH    = parseInt(sec_css.getPropertyValue("width"));

  config.SEC_OFFSET   = -parseInt(sec_css.getPropertyValue("margin-top"));



  if (hour_css.getPropertyValue("content") == "none")

  {

    config.GRAPHICAL  = false;

    config.HOUR_COLOR = hour_css.getPropertyValue("background-color");

    config.MIN_COLOR  = min_css.getPropertyValue("background-color");

    config.SEC_COLOR  = sec_css.getPropertyValue("background-color");

  }

  else

  {

    config.GRAPHICAL      = true;

    config.HOUR_IMAGE.src = hour_css.getPropertyValue("content");

    config.MIN_IMAGE.src  = min_css.getPropertyValue("content");

    config.SEC_IMAGE.src  =  sec_css.getPropertyValue("content");

  }

}


function drawShadow(offset, hand, angle)

{

  ctx.save();

  ctx.translate(config.WIDTH/2,config.HEIGHT/2);

  ctx.translate(0,offset);

  ctx.rotate(angle);

  ctx.translate(-(config[hand+"_WIDTH"]/2),config[hand+"_OFFSET"]);

  ctx.fillStyle = "rgba(0,0,0,0.25)";

  ctx.fillRect(0,0,config[hand+"_WIDTH"]+1,config[hand+"_LENGTH"]);

  ctx.restore();

}



function drawHand(hand, angle)

{

  ctx.save();

  ctx.translate(config.WIDTH/2,config.HEIGHT/2);

  ctx.rotate(angle);

  ctx.translate(-(config[hand+"_WIDTH"]/2),config[hand+"_OFFSET"]);

  if (!config.GRAPHICAL)

  {

    ctx.fillStyle = config[hand+"_COLOR"];

    ctx.fillRect(0,0,config[hand+"_WIDTH"],config[hand+"_LENGTH"]);

  }

  else

  {

    ctx.drawImage(config[hand+"_IMAGE"]);

  }

  ctx.restore();

}





function clock()

{

  var now = new Date();

  var hours     = now.getHours()%12

      ,minutes  = now.getMinutes()

      ,seconds  = now.getSeconds()

      ,mseconds = config.SMOOTH?now.getMilliseconds():0;



  dock.innerHTML = hours + ":" + minutes + ":" + seconds;

  var h_a = (hours/6 + minutes/360 + seconds/21600)*Math.PI+Math.PI;

  var m_a = (minutes/30 + seconds/1800)*Math.PI+Math.PI;

  var s_a = (seconds/30 + mseconds/30000)*Math.PI+Math.PI;

  if (old_s_a != s_a)

  {

    document.getElementById("date").textContent = now.getDate();

    ctx.globalCompositeOperation = "copy";

    // Draw Hours

    if (config.HAS_SHADOW)

    {

      drawShadow(1, "HOUR", h_a);

    }

    ctx.globalCompositeOperation = "source-over";

    drawHand("HOUR", h_a)



    // Minutes

    if (config.HAS_SHADOW)

    {

      drawShadow(2, "MIN", m_a);

    }

    drawHand("MIN",m_a);

    // Seconds

    if (config.HAS_SHADOW)

    {

      drawShadow(3, "SEC", s_a);

    }

    drawHand("SEC",s_a);

  }

  old_s_a = s_a;

  setTimeout(clock,config.TIMEOUT);

}

var skinCounter = 0;

skinCounter = widget.preferenceForKey('skinCounter');

if(!skinCounter) skinCounter = 0;

window.addEventListener("click",setSkin,false);

function setSkin(e) {

  var d = document.getElementById('mainview');

  if (++skinCounter == config.SKINS.length)

  {

    skinCounter = 0;

  }

  d.className = config.SKINS[skinCounter];

  configure();

  widget.setPreferenceForKey(skinCounter, 'skinCounter');

}

离线nikshuang2
只看该作者 1楼 发表于: 2009-08-04
定起来阿,这应该是标准的JS,为什么就不能正常显示呢
离线machou

只看该作者 2楼 发表于: 2009-09-04
QT有自己的脚本QScript,好像不支持Javascript
离线wlzxlc
只看该作者 3楼 发表于: 2011-04-17
我用qwebview写了一个谷歌的电子地图导航,脚本中用的也是javascript,在虚拟机的linux下可以运行,但是交叉编译后放到mni2410开发板上就不行,不知道为什么,而且我还发现用webview->page()->mainFrame()->evaluateJavaScript("setXY(\"37\",\"48\")")传值的时候是可以的,但是用webview->page()->mainFrame()->evaluateJavaScript("setXY(37,48)")就不行
离线王晓辉
只看该作者 4楼 发表于: 2012-02-03
我也有这样的问题,请问你的解决了没有??
O(∩_∩)O~
离线XChinux

只看该作者 5楼 发表于: 2012-02-06
看看在chrome下面能否正常运行,再看看用qt-demo中的那个qt-browser能否正常运行
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
快速回复
限100 字节
 
上一个 下一个