Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Help with JavaScript type
QtWS25 Last Chance

Help with JavaScript type

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 3 Posters 670 Views
  • 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
    pderocco
    wrote on last edited by pderocco
    #1

    I'm asking this here because it may be peculiar to the QML JavaScript engine.

    What value of x could give me the following results:

    x !== null
    x !== undefined
    typeof x === "object"
    String(x) === "?"
    Object.getPrototypeOf(x) === undefined

    In my program x could be null, but the first test says otherwise, or it could be a Uint8Array, but the string version of that is a comma-separated list of numbers. What, other than a quoted question mark, displays as a question mark?

    I'm wondering if it could be a reference to an object that has been garbage collected, and I've discovered some sort of bug in the engine.

    JonBJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Can you post a minimal code sample that shows the situation you describe ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      P 1 Reply Last reply
      0
      • P pderocco

        I'm asking this here because it may be peculiar to the QML JavaScript engine.

        What value of x could give me the following results:

        x !== null
        x !== undefined
        typeof x === "object"
        String(x) === "?"
        Object.getPrototypeOf(x) === undefined

        In my program x could be null, but the first test says otherwise, or it could be a Uint8Array, but the string version of that is a comma-separated list of numbers. What, other than a quoted question mark, displays as a question mark?

        I'm wondering if it could be a reference to an object that has been garbage collected, and I've discovered some sort of bug in the engine.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @pderocco
        Don't know, but don't forget you can try various instanceOf() if you can guess what the (base) type might be?

        P 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Can you post a minimal code sample that shows the situation you describe ?

          P Offline
          P Offline
          pderocco
          wrote on last edited by
          #4

          @SGaist Unfortunately, when I try a simple program that does what the real program is (supposedly) doing, it works fine. So I'm trying to deduce it from the other end, by figuring out what the type of the object is.

          1 Reply Last reply
          0
          • JonBJ JonB

            @pderocco
            Don't know, but don't forget you can try various instanceOf() if you can guess what the (base) type might be?

            P Offline
            P Offline
            pderocco
            wrote on last edited by pderocco
            #5

            @JonB The only two things I should get are null or a Uint8Array. When the failure occurs, it doesn't compare equal to null, and x instanceof Uint8Array returns false. Also, x.prototype returns undefined. Other than null, what kinds of things can report a type of object, but not have a prototype?

            Update: Apparently, things like Uint8Array report a type of object, and have a prototype of undefined rather than null. I guessed that I may have used an ArrayBuffer instead of a Uint8Array, and sure enough, x instanceof ArrayBuffer returns true. So console.log displays an ArrayBuffer as a question mark.

            So, problem solved I guess. Thanks for pointing me to instanceof.

            JonBJ 1 Reply Last reply
            0
            • P pderocco

              @JonB The only two things I should get are null or a Uint8Array. When the failure occurs, it doesn't compare equal to null, and x instanceof Uint8Array returns false. Also, x.prototype returns undefined. Other than null, what kinds of things can report a type of object, but not have a prototype?

              Update: Apparently, things like Uint8Array report a type of object, and have a prototype of undefined rather than null. I guessed that I may have used an ArrayBuffer instead of a Uint8Array, and sure enough, x instanceof ArrayBuffer returns true. So console.log displays an ArrayBuffer as a question mark.

              So, problem solved I guess. Thanks for pointing me to instanceof.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @pderocco
              Yep, that's why I suggested instanceOf() :) JS is odd!

              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