Reputation: 22916
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
.
UPDATE:
I tried 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];
Upvotes: 0
Views: 2214
Reputation:
According to your update, your JavaScript function expects a string argument. The simplest approach should look like this:
QString info = QString("constructFileName('%1')").arg(centerPointsList[i].toFloat());
QVariant holdInformation = map->page()->mainFrame()->evaluateJavaScript(info);
However, in general this is not completely safe - if the interpolated argument %1
contains backslashes, double quotes or other special symbols, they need to be escaped first. I cannot comment on how that should be done, since I have never worked with Qt :)
Upvotes: 1