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. Variable declarations
Qt 6.11 is out! See what's new in the release blog

Variable declarations

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 1.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.
  • M Offline
    M Offline
    MagicCoder
    wrote on last edited by
    #1

    How do I declare a global and non-global variable?
    I tried "var Key = 1"
    but I am having error when I try to debug.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dmcr
      wrote on last edited by
      #2

      You can include a .js file and use "var key = 1" in this js file, your variable will be visible in the QML file.

      I don't know if there is a way of declaring "global" variable for all QML files.

      dmcr

      1 Reply Last reply
      0
      • D Offline
        D Offline
        deimos
        wrote on last edited by
        #3

        bq. I don’t know if there is a way of declaring “global” variable for all QML files.

        yes, with

        @.pragma library
        vak key = 1;@

        on top of the .js code

        Edit: if I remember well, in Creator when you create a new .js file, it asks about create a stateless library
        Edit 2: "here":http://qt-project.org/doc/qt-4.8/qdeclarativejavascript.html#stateless-javascript-libraries a reference

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dmcr
          wrote on last edited by
          #4

          Thanks for the link.
          I have looked a time ago and the documentation was not so good, so at that time i did not succeed, ( didn't use Qt.include("factorial.js") in another js! ) but it works!

          dmcr

          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