PDA

View Full Version : search and replace in js with qt



Same_Andy
29th January 2016, 21:00
Hello,

I have the following problem. I want to replace a string of a variable in a JavaScript file with a function in Qt.



url = "qrc:/res/res/text.pdf";

void WebView::open()
{
QFile currentFile("qrc:/res/res/pdf-viewer.js");
QString s;
if(!currentFile.open(QFile::WriteOnly|QFile::Text) )
{
return;
}
QTextStream in(&currentFile);
s= in.readAll();
s.replace("$STRINGPDF",QString(url));
qDebug()<<s;
currentFile.close();
}

he finds the variable not in the specified file. Because you can see I have the absolute paths of the files specified.

please help me

thanks

ChrisW67
30th January 2016, 00:54
You open the file for writing: probably fails because you cannot write to an embedded resource.
If it opened you then attempt to read from it: probably fails silently and returns an empty string.
You replace all occurrences of "$STRINGPDF" in the empty string.
Your debug output is empty.