Yes, you can. I do this in my application. For instance:
QWebFrame* frame = ui->webView->page()->mainFrame();
frame->evaluateJavaScript(readFile(":/scripts/foo.js"));
Where readFile is a function that reads the contents of a file into a string. For instance:
QString readFile (const QString& filename)
{
QFile file(filename);
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream stream(&file);
return stream.readAll();
}
return "";
}
Since the file name begins with:, it is read from the resource file. The resource file should contain /scripts/foo.js, obviously.
source
share