Qt script engine problems
-
I ran across a problem ("described here":http://qt-project.org/forums/viewthread/30161/) that seems to indicate some anomalous behavior in the Qt script engine as implemented in QtWebKit. I don't know how universal this "problem" is but my understanding is that the QtWebKit script engine is the same as the regular Qt script engine so I'm posting the problem here in the hopes of getting some help. The problem can be illustrated using the follow html:
@<!DOCTYPE html5>
<html>
<head>
<title>Alert test</title>
[removed]
window.onload=function(){
var tst="x&";
alert("tst0="+tst);
tst="<x&";
alert("tst1="+tst);
tst="<x&";
alert("tst2=\n"+tst);
tst="\n<&";
alert("tst3="+tst);
}
[removed]
</head>
<body>
</body>
</html>@(note; the code block has inserted an extra backslash in tst3 which is not present in the actual code and replaced script tags by [removed])
All of these alert boxes should just contain the strings defined in tst. That is, the four alert boxes should display:
first alert box display:
tst0=x&second alert box display:
tst1=<x&third alert box display:
tst2=
<x&fourth alert box display:
tst3=
<&All the major browsers (IE,FF,CHROME,SAFARI) produce these results but the Qt script engine produces the anomalous results:
first alert box display:
tst0=x&second alert box display:
tst1=<x&third alert box display:
tst2=
<x&fourth alert box display:
tst3=
<&Only tst1 results are identical to the results produced by the major browsers. It appears that somehow the text string is parsed by the alert method but I haven't been able to figure out the parsing algorithm . As can be seen from these results preceding a string of characters with a newline seems to cause characters for greater than (>), less than (<) and ampersand (&) to be replaced by their entity representations. Unfortunately it seems to be somewhat more complicated than this as can be seen from the txt0 and txt1 results.
If anyone know the algorithm used by the script engine or knows how to prevent the alert method from inserting entities please let me know as, for me, this is a showstopper.
-
In case others may run into this problem I managed to find a reliable work around by wrapping a QMessageBox in a QObject as a Q_INVOKABLE alert function and then connecting the object to a script.