最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to call evaluateJavaScript() function from Qt? - Stack Overflow

programmeradmin4浏览0评论

I am not able to call a javascript function from QT .

I am using the below code

QT code :
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>
<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>

Can anyone give me any pointers why the Javascript function is not getting called.

I am not able to call a javascript function from QT .

I am using the below code

QT code :
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>
<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>

Can anyone give me any pointers why the Javascript function is not getting called.

Share Improve this question edited Sep 26, 2012 at 5:12 Aquarius_Girl 22.9k69 gold badges248 silver badges441 bronze badges asked Sep 25, 2012 at 7:43 taruntarun 811 silver badge7 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

I know this post is old but in case someone has the same:

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);

Now by right clicking->inspect, console, you would have seen the JS interpret error.

You should have lower case 'c' in 'onclick':

<input type="button" value="Click me!" onclick="displayhello()">

QVariant holdInformation = map->page()->mainFrame()->evaluateJavaScript (QString ("displayhello ()"));

Replace map by your desired class name.

Also, try using onload.
<body onload = "displayhello()" topmargin = "0" leftmargin = "0">

发布评论

评论列表(0)

  1. 暂无评论