PDA

View Full Version : QJSEngine throw error from native function in c++



anbu01
24th February 2016, 14:03
Hi,
I need an equivalent function in QJSEngine for the following code in QScriptEngine:-


return context->throwError( QScriptContext::SyntaxError, "Invalid Value");

I could not find any usefule function in QJSEngine docs to throw an error.

anda_skoa
24th February 2016, 14:44
I know it is not the same thing, but http://doc.qt.io/qt-5/qqmlengine.html#qmlInfo can be used to print related warning.

Cheers,
_

anbu01
25th February 2016, 07:03
Thanks anda_skoa i can check on that and let you know but the real killer is in LiScriptEngine we have QScriptSyntaxCheckResult QScriptEngine::checkSyntax(const QString & program) which is more useful to identify the type of error occured when engine executes a program.But in JSEngine the return value is JSValue where we cannot identify the type since there is no real error object in JSEngine.On going through the docs i can see functions like isError() and some properties of error like line,stack,name... but none of this is equivalent to checkForSyntax.Any idea on this problem or this is not possible in JSEngine.

anda_skoa
25th February 2016, 09:08
Ah, interesting, didn't know about checkSyntax().

My guess is that nobody has needed that yet in QJSEngine so nobody has added it yet.

Cheers,
_