How to pass an argument to evaluateJavaScript function?
Code:
for (int i = 0; i < centerPointsList.size (); i++)
{
QVariant holdInformation
= map
->page
()->mainFrame
()->evaluateJavaScript
(QString ("constructFileName (%1).arg (centerPointsList[0].toFloat())"));
QList <QVariant> allListObj
= holdInformation.
toList ();
QList <QVariant> fileNamesList
= allListObj
[0].
toList ();
std :: cout << fileNamesList[0].toFloat() << "================= \n";
}
This results in:
Quote:
"SyntaxError: Parse error on line:1 Source:undefined"
Segmentation fault
I am guessing that the error is in the way I am passing the list item to the function evaluateJavaScript.
Re: How to pass an argument to evaluateJavaScript function?
See if this works
Code:
QString ("constructFileName (%1).arg (centerPointsList[0].toFloat())");
//Change this as below QString ("constructFileName (%1)").
arg(centerPointsList
[0].
toFloat());
Re: How to pass an argument to evaluateJavaScript function?
I tried your way like this:
Code:
for (int i = 0; i < centerPointsList.size (); i++)
{
QVariant holdInformation
= map
->page
()->mainFrame
()->evaluateJavaScript
(QString ("constructFileName (%1)").
arg (centerPointsList
[0].
toFloat ()));
which resulted in:
Quote:
"TypeError: Result of expression 'centerPointFileName.split' [undefined] is not a function. on line:65 Source:file:///..../index.html"
The function constructFileName (in Javascript) is as follows:
Code:
function constructFileName (centerPointFileName)
{
var removeSpaces = centerPointFileName.split (" ");
var fileNameWithoutSpaces = "", i;
for (i = 0; i < removeSpaces.length; i++)
fileNameWithoutSpaces = fileNameWithoutSpaces + removeSpaces [i];
Re: How to pass an argument to evaluateJavaScript function?
If I am not mistaken the error is inside Java script, not in Qt Code.
Further the error says "TypeError", you are passing a float as argument to JS, where as it expects centerPointFileName (whatever type it is), a spilt on it is called, not sure what will a spilt on float do. (that too split with space).
I guess JS is expecting a multi word string.
Re: How to pass an argument to evaluateJavaScript function?
Float does not have a "split" method, only String does.
Re: How to pass an argument to evaluateJavaScript function?
I cross posted this on stackoverflow and the solution presented in the below link solved my error.
http://stackoverflow.com/a/14170076/462608