QJSEngine and error line



  • Hi,

    I'm using the new QJSEngine and I'm trying to get the error line number (in case of error of course).
    Currently I'm handling errors as documented:

    • if (result.isError()) result.toString().toUtf8() ...

    but actually, the string is very poor: e.g. "SyntaxError: Syntax error"
    I would like to get at least a line number. Contextual information would be also welcome.
    Is it possible with the QJSEngine? (I'm using Qt 5.3.0)

    Dominique


  • Moderators

    Hi Dominique,

    It looks to me like a missing feature in QJSEngine. The documentation mentions line numbers, but the API doesn't seem to provide a way to retrieve it.

    I might have missed something though. I suggest taking this to the Interest mailing list -- subscribe to the list and post your question there. Qt engineers are active on this list, and they will be able to tell you if there's currently a way to do what you want. (If not, you can submit a feature request)



  • Thanks for the pointer to the list.
    I've got the answer:
    Try to access the properties "message", "fileName" and "lineNumber".
    if (result.isError())
    qDebug() << result.property("fileName").toString();
    result is a JavaScript Error object iff isError returns true.


  • Moderators

    @fober
    Great! Thanks for sharing the answer.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.