如何将用于评估的Javascript放入QWebView的evaluatejavascript函数中
编辑: 编辑太多 :doh:
这次我已经确定了问题所在。我将 Javascript 代码传递给 evaluatejavascript 函数的方式存在缺陷。 QWebView 的。
使用 Google 地图的 API,当我单击附加到包含以下代码的插槽的按钮时
this->page()->mainFrame()->evaluateJavaScript (QString ("Open(%1,2)") ).arg ( point.x ()).arg (point.y ()) );
显示与相关位置相关的地图。
现在,如果我想向特定坐标添加标记,我会这样做:
this->page()->mainFrame()->evaluateJavaScript (QString ("addMarker (%1, %2)").arg (point.x ()).arg (point.y ()) );
此代码不会执行。有什么想法吗?
除此之外,如何将用户定义函数添加到evaluateJavaScript中进行评估?
EDIT:
Too many edits :doh:
I have identified the problem this time. There is a flaw in the way I am passing the Javascript code to the evaluatejavascript func. of QWebView.
Using Google maps's API, when I click a pushButton attached to the slot holding the below code
this->page()->mainFrame()->evaluateJavaScript (QString ("Open(%1,2)").arg ( point.x ()).arg (point.y ()) );
the map pertaining to the location in question gets displayed.
Now if I want to add a marker to a particular coordinate, I do:
this->page()->mainFrame()->evaluateJavaScript (QString ("addMarker (%1, %2)").arg (point.x ()).arg (point.y ()) );
This code doesn't execute. Any ideas?
Besides this, what is the way to add a user defined function to evaluateJavaScript for evaluation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
终于找到答案了!
任何必须从函数 evaluateJavaScript 调用的 Javascript 函数都应该在 C++ 源代码的 html 文件(包含在)中定义,如下所示:
现在,我不再创建新的添加标记函数,而是已将其代码添加到下面定义的 Open 函数中:
Finally found the answer!
Any Javascript function which has to be called from function evaluateJavaScript is supposed to be defined in an html file (included in) the C++ source, as shown below:
Now instead of creating a new add marker function, I have added its code in the Open function defined below: