Pass data from QT to javascript function
I have a question that i really don't know.
Here is the my code.
Code:
QFile file( ":/direction.js");
{
msg.setText("Fail");
msg.exec();
}
else
{
from = "6";
QString functions
= file.
readAll();
QWebFrame* frame = ui->webView->page()->mainFrame();
frame->evaluateJavaScript( functions );
frame->evaluateJavaScript(script);
}
and the content of direction.js like :
Code:
function Direction (from)
{
alert("This is Direction");
alert(from);
}
But i am very confused with the value of QString from.
when i put it : from="8".It run OK
But when i put it : from="a".It can not run.
If you know this problem.Please explain it for me.
Thanks and best regards!
Re: Pass data from QT to javascript function
I am not a javascript guy but isn't correct while needs quotation marks?
Re: Pass data from QT to javascript function
Thanks very much. I have to add in QT as follow :
from = "\""+myString+"\"";
Re: Pass data from QT to javascript function
Also not sure again, but simple quotations marks should be allowed as well. Thus there is no need to escape the quotation marks which makes the code more readable (in my opinion):
Code:
from
= QString("'%1'").
arg(myString
);