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 Update on Monday, May 27th 2025

The replacement of "window" object in Javascript

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 1.6k 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.
  • B Offline
    B Offline
    benlau
    Qt Champions 2016
    wrote on 24 Nov 2013, 16:23 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
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 24 Nov 2013, 19:08 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
      • B Offline
        B Offline
        benlau
        Qt Champions 2016
        wrote on 25 Nov 2013, 01:20 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
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 25 Nov 2013, 05:23 last edited by
          #4

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

          (Z(:^

          1 Reply Last reply
          0
          • B Offline
            B Offline
            benlau
            Qt Champions 2016
            wrote on 25 Nov 2013, 06:24 last edited by
            #5

            That will throw :

            @
            ReferenceError: someObject is not defined
            @

            1 Reply Last reply
            0

            1/5

            24 Nov 2013, 16:23

            • Login

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