PDA

View Full Version : How to pass an argument to evaluateJavaScript function?



TheIndependentAquarius
5th January 2013, 07:42
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:


"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.

Santosh Reddy
5th January 2013, 07:58
See if this works


QString ("constructFileName (%1).arg (centerPointsList[0].toFloat())"); //Change this as below
QString ("constructFileName (%1)").arg(centerPointsList[0].toFloat());

TheIndependentAquarius
5th January 2013, 08:13
I tried your way like this:


for (int i = 0; i < centerPointsList.size (); i++)
{
QVariant holdInformation = map->page ()->mainFrame ()->evaluateJavaScript (QString ("constructFileName (%1)").arg (centerPointsList [0].toFloat ()));


which resulted in:

"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:


function constructFileName (centerPointFileName)
{
var removeSpaces = centerPointFileName.split (" ");
var fileNameWithoutSpaces = "", i;
for (i = 0; i < removeSpaces.length; i++)
fileNameWithoutSpaces = fileNameWithoutSpaces + removeSpaces [i];

Santosh Reddy
5th January 2013, 08:29
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.

wysota
5th January 2013, 09:27
Float does not have a "split" method, only String does.

TheIndependentAquarius
5th January 2013, 09:45
I cross posted this on stackoverflow and the solution presented in the below link solved my error.
http://stackoverflow.com/a/14170076/462608