[Solved] How to pass data from Qt application to Javascript function?
-
Dear all friends,
Qt Application
@ QString from;
QFile file( ":/test.js");
if ( !file.open(QIODevice::ReadOnly | QIODevice::Text) )
{
from = "Hello!";
QString functions = file.readAll();
QWebFrame* frame = ui->webView->page()->mainFrame();
frame->evaluateJavaScript( functions );QString script = QString("myFunction(%1);").arg( from ); frame->evaluateJavaScript(script); }
@
Is there somethings wrong with my function call?
Thanks
Here is test.js
@ function myFunction (from)
{ alert("This is testing... "); alert(from); }@
-
It would most likely be simpler to just stick an QObject into the JS context via "QWebFrame::addToJavaScriptWindowObject(...)":http://doc.qt.nokia.com/4.7-snapshot/qwebframe.html#addToJavaScriptWindowObject and interact over that one.
This works better when you have the JS under your control:-)
-
I am sure you will find some using your search engine of choice.