如何从Qt调用evaluateJavaScript()函数? [英] How to call evaluateJavaScript() function from Qt?
问题描述
我无法从QT调用javascript函数。
I am not able to call a javascript function from QT .
我使用以下代码
QT代码:
QWebFrame * frame = m_d-> m_webView-> page() - > mainFrame();
frame-> evaluateJavaScript(displayhello());
Here `displayhello()` is the `Javascript` function defined in the HTML file.
HTML code:
HTML code :
<html>
<head>
<script type="text/javascript" src="" />
<script type="text/javascript">
function displaymessage(str)
{
alert(str);
}
function displayhello()
{
alert("Hello");
}
</script>
</head>
<body>
<form>
<input type="button" value="Click me!" onClick="displayhello()">
</form>
</body>
</html>
任何人都可以给我任何指针,说明为什么没有调用Javascript函数。
Can anyone give me any pointers why the Javascript function is not getting called.
推荐答案
我知道这个帖子已经过时了,但是如果有人有相同的话:
I know this post is old but in case someone has the same:
经常检查开发工具,查看JavaScript控制台告诉您的内容。
您可以通过在QT主函数中添加此行来启用devtools
Always check Dev Tools to see what the JavaScript console tells you. You can enable devtools by adding this line tou your QT main function
QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
现在通过右键单击 - > inspect,console,你会看到JS解释错误。
Now by right clicking->inspect, console, you would have seen the JS interpret error.
这篇关于如何从Qt调用evaluateJavaScript()函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!