Results 1 to 4 of 4

Thread: QJSEngine throw error from native function in c++

  1. #1
    Join Date
    Feb 2014
    Posts
    60
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default QJSEngine throw error from native function in c++

    Hi,
    I need an equivalent function in QJSEngine for the following code in QScriptEngine:-

    Qt Code:
    1. return context->throwError( QScriptContext::SyntaxError, "Invalid Value");
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QJSEngine throw error from native function in c++

    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,
    _

  3. #3
    Join Date
    Feb 2014
    Posts
    60
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QJSEngine throw error from native function in c++

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QJSEngine throw error from native function in c++

    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,
    _

Similar Threads

  1. QJSEngine and error line
    By fober in forum Qt Programming
    Replies: 0
    Last Post: 3rd April 2015, 09:16
  2. Replies: 10
    Last Post: 3rd February 2015, 20:24
  3. Can I throw exceptions from the constructor?
    By 8Observer8 in forum Newbie
    Replies: 4
    Last Post: 27th August 2014, 09:39
  4. Why can I get QT Libraries to throw ASSERT errors
    By grabalon in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2010, 00:29
  5. Send a Image throw a QDataStream
    By gt.beta2 in forum Newbie
    Replies: 5
    Last Post: 20th March 2009, 23:07

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.