Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Use variable in import statement?

    QML and Qt Quick
    2
    5
    687
    Loading More Posts
    • 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
      JeTSpice last edited by

      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 Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        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 Reply Quote 0
        • J
          JeTSpice last edited by

          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 Reply Quote 0
          • sierdzio
            sierdzio Moderators last edited by

            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 Reply Quote 0
            • J
              JeTSpice last edited by

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

              1 Reply Last reply Reply Quote 0
              • First post
                Last post