Unsolved calling javascript function from Qt Console application
-
-
@jsulm same result except /n is removed
-
@SherifOmran Did you try to call https://doc.qt.io/qt-5/qscriptengine.html#uncaughtException to see whether there is an exception and if so what it is?
-
i did not try because this is a very simple example. I took another approach to create a browser and load the js file
-
@SherifOmran
Creating a browser, if you do not want it for other purposes, just to evaluate some JS is a very "heavyweight" solution. Just saying.... -
@SherifOmran You're adding a browser because it is a "very simple example"?!
In my opinion it would be way faster and easier to check for exceptions instead (you should do this anyway)... -
yes that is true, and it will be heavy, but i intent to run very complicated js file and if i can not run a simple test function, how will it be with a complicated script !
If any body can provide me a working example, this would be great. -
qDebug() << contents; QScriptValue fun = engine.evaluate(contents); qDebug() << engine.hasUncaughtException(); QScriptValueList args; args << 1 << 2; QScriptValue threeAgain = fun.call(QScriptValue(), args); qDebug() << engine.hasUncaughtException(); qDebug() << threeAgain.isValid();
would be an improvement which would take you 10 seconds.
-
@JonB said in calling javascript function from Qt Console application:
qDebug() << engine.hasUncaughtException();
Same result ! I am compiling under Mac high sierra 10.13.6
QString contents = "function myfunc(p1, p2) { return p1*p2; }"; QScriptValue fun = engine.evaluate(contents); qDebug() << engine.hasUncaughtException(); QScriptValueList args; args << 1 << 2; QScriptValue threeAgain = fun.call(QScriptValue(), args); qWarning() << engine.hasUncaughtException(); bool A= threeAgain.isValid();
-
Please test it on your side and let me know, if this simple code works. May be this is a bug ? I am using clang under mac high sierra.