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. Use variable in import statement?

Use variable in import statement?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 978 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.
  • J Offline
    J Offline
    JeTSpice
    wrote on last edited by
    #1

    Is there a way to do something like meta-meta data in pure qml?

    import parent.someVariable
    

    ...where someVariable is declared in a parent file?

    In some languages, there are meta tags which are swapped out with script/code before the file gets compiled. Wondering if QML has any provision for that.

    Alternatively, is there a way to load a qml file, and then alter something in its scripting before it goes to the engine?

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

      Accessing parent does not require any import. Parent is always available, for all components, so you can just use the parent property. Just make sure that at runtime it is available in the actual parent of your component.

      I think that using File Selectors can also help you in your case.

      (Z(:^

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JeTSpice
        wrote on last edited by
        #3

        Ok, thanks for the reply. I should not have put the "parent" reference in my question. I'm wondering if QML has any way of doing metadata. For instance literally typing something like this in code,

        import someVariable
        

        where someVariable is declared elsewhere, as a global.

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

          No. Global variables are just global, there is no need to import them. For example if you declare root context property "engine", you can access engine properties from any QML file in your project, with no need for an import statement.

          If you do want to have an explicit import, consider registering a QML singleton or adding a C++ component which is a singleton behind the scenes.

          (Z(:^

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JeTSpice
            wrote on last edited by
            #5

            ok, thanks again. I'm asking about meta tags and meta data, not globals. probably qml doesn't have it.

            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