【发布时间】:2016-09-28 21:52:43
【问题描述】:
我的 qrc 文件如下所示:
<qresource prefix="/web">
<file alias="assets.js">../web/assets.js</file>
<file alias="index.html">../web/index.html</file>
</qresource>
在assets.js里面只添加了弹出提示功能:
function myFunction()
{
window.alert("Hello from assets.js");
}
在 index.html 内添加另一个 javascript 用于弹出警报,加载 assets.js 并添加 2 个按钮。第一个从外部 javascript 文件 (assets.js) 调用弹出窗口,第二个调用嵌入到 index.html 文件中的 javascript:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
function localFunction()
{
window.alert('HTML loaded');
}
</script>
<script src="assets.js"></script>
<button onclick="myFunction()">External JS</button>
<button onclick="localFunction()">Local JS</button>
</body>
</html>
现在,当我尝试在 qtwebkit 中加载 index.html 时:
webView->load(QUrl(QStringLiteral("qrc:/web/index.html")));
我可以看到 index.html 已经加载好(我可以看到 2 个按钮) 单击应该调用本地(嵌入html)javascript的按钮时,它可以工作。 单击第二个按钮没有任何作用。
外部 assets.js 似乎没有正确加载。 有什么建议可以让它工作吗?
谢谢。
【问题讨论】:
-
this 问题的答案可能会有所帮助。
标签: c++ windows qt qtwebkit qtwebview