Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QtScript Error objects
Qt 6.11 is out! See what's new in the release blog

QtScript Error objects

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pkj__
    wrote on last edited by
    #1

    Hi forum,
    Making applications scriptable document describes in the last section about Error object. It says:

    Error.prototype.backtrace
    This function returns a human-readable backtrace, in the form of an array of strings.
    Error objects have the following additional properties:
    lineNumber: The line number where the error occurred.
    fileName: The file name where the error occurred (if a file name was passed to QScriptEngine::evaluate()).
    stack: An array of objects describing the stack. Each object has the following properties:
    functionName: The function name, if available.
    fileName: The file name, if available.
    lineNumber: The line number, if available."

    I have this code which I added in qtscript helloscript example(helloscript.js file)//does nothing but executes the program line by line...
    @function bar(){
    try{ Tag.nonsense = 83 ;}
    catch (e){this.err = e; print(e instanceof Error);//true}
    }
    var x = bar();
    print(this.err);//ReferenceError: Can't find variable: Tag
    print(this.err.backtrace);//undefined
    print(this.err.linenumber);//undefined
    print(this.err.stack);//undefined@

    The outputs I have written in comments. Clearly this is a departure from what is written in the document as the error object having those properties. What am i missing??
    Regards,
    PKJ

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tucnak
      wrote on last edited by
      #2

      Hello, ~pkj__!

      I think that your problem lies in Tag object. Try to append to your code line:
      @
      var Tag = {};
      @

      It should create object tag and you won't have any errors. Now, you get this error because you don't have variable Tag. If you want to enable it in C++ code, you should set QObject::objectName, another way - you should init it in js code.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pkj__
        wrote on last edited by
        #3

        I introduced the Tag, knowing that it will give error. My question is not why the error is being shown. Albeit, why is it that errorObject.backtrace is showing undefined. It has been mentioned in "making applications scriptable" document that Error objects have backtrace as a prototype property.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tucnak
          wrote on last edited by
          #4

          Hmm.. It looks strange. AFAIK, this coe must work.

          But Chrome can't get x.backtrace also.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved