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. The replacement of "window" object in Javascript
Forum Updated to NodeBB v4.3 + New Features

The replacement of "window" object in Javascript

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 1.6k 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.
  • benlauB Offline
    benlauB Offline
    benlau
    Qt Champions 2016
    wrote on last edited by
    #1

    Whatever we declared a global variable in Javascript under browser, it will be added to the "window" object automatically. Then we could check did a global variable/object declared by looking at the window object.

    However, it don't have "window" object in Qt Quick. Do it have any replacement? So that I can check did a global variable declared?

    Thanks.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      In Qt Quick, global stuff (for QML and JS) is added to the rootContext of the QML engine. You access it directly, without specifying any parent object.

      As for pure JavaScript, AFAIK, all contexts are separate, so you can't specify anything truly global. But my knowledge of JS is too limited to say for sure.

      (Z(:^

      1 Reply Last reply
      0
      • benlauB Offline
        benlauB Offline
        benlau
        Qt Champions 2016
        wrote on last edited by
        #3

        Thanks for your reply. In fact, I would like to configure the variable of a Javascript instance and the method I chosen is context object. However, as the context object is passed by the C++ program, it will throw "Reference Error" under Qt Designer.

        To avoid the error , I would like to check did the context object / global variable declared before access. But unfortunately it don't have the "window" object under Qt Quick.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          @
          if (someObject == undefined) {
          // it is not defined
          } else {
          // we are good to go :)
          }
          @

          (Z(:^

          1 Reply Last reply
          0
          • benlauB Offline
            benlauB Offline
            benlau
            Qt Champions 2016
            wrote on last edited by
            #5

            That will throw :

            @
            ReferenceError: someObject is not defined
            @

            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