PDA

View Full Version : qtscript



wookoon
24th June 2010, 07:53
Hello everyone,

Now I want do a formula editor with qt,which provide an interface to user to edit there own formula by

qtscript. So it needs some base functions just like add,subtract and so on.

I want write these functions in a javascript file, and then invoke this file in my qtscript text. But I try some

ways to invoke that file,it is not effective.

Anyone can give me some suggestions?

wookoon
24th June 2010, 09:17
no one reply me.
I tell a way I just hava try.



function include_js(path,reload)
{
var scripts = document.getElementsByTagName("script");
if (!reload)
for (var i=0;i < scripts.length;i++)
if (scripts[i].src && scripts[i].src.toLowerCase() == path.toLowerCase() ) return;
var sobj = document.createElement('script');
sobj.type = "text/javascript";
sobj.src = path;
var headobj = document.getElementsByTagName('head')[0];
headobj.appendChild(sobj);
}

include_js("test.js",0);



but this is the warning: Can't find variable: document. ..

squidge
24th June 2010, 09:32
Correct. QtScript doesn't have document variable. Its not running from within a html page, so there is none.

Please check the QtScript examples directory.

wookoon
24th June 2010, 09:54
Correct. QtScript doesn't have document variable. Its not running from within a html page, so there is none.

Please check the QtScript examples directory.

yes,I know,but in my script,I need use "test.js" this file.

so is there any ways to do?

FFox
4th July 2010, 11:53
Mhm why not use the build in functionality.

I did something like this:



QScriptEngine engine;
for (int x=0; x<size_x ; x++)
{
engine.globalObject().setProperty("x",x);
double value=engine.evaluate(QString("with (Math) {")
+mUi.mpLineEditParserFunctionString>text()
+QString("}")).toNumber();
my_function->SetValuel(x,value);
}


then people can type their formulas into the lineedit like x*sin(x)*exp(-x*x)