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. Passing Data from QML to QML via Loader
QtWS25 Last Chance

Passing Data from QML to QML via Loader

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

    Hello guy,

    I search for that kind of topic but didn't find any good solution.
    What I need is a way to pass data to let's say a qml screen file.
    The qml has to take the passed data into account. For example
    user rights etc.
    How can I pass data to a qml file which is loaded via a Loader {} ?
    If i set the properties of the qml Item the qml file is already processed
    and i can't set the properties before loading or processing the qml file.

    What is the appropriate way to pass data to a qml file?
    It seems that propertie-bindings will not work in that case.

    1 Reply Last reply
    0
    • O Offline
      O Offline
      onek24
      wrote on last edited by
      #2

      I don't think that you can pass properties to a QML File before it is going to be loaded but you can pass it after it has been loaded by for example accessing the childrens of the loader and setting the property in it.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Schneidi
        wrote on last edited by
        #3

        Yep I guess the way it works is to load the qml file first.
        Then access the loader.item which is the loaded qml file
        and set the properties of the Item.

        This is what I already tried but not in a consistent way.

        For example:

        @
        property string main_text: "default"
        property int screen_mode: 0

        Item {
            anchors.fill: parent
            visible: {
                 if (screen_mode == 1)
                     true
                 else
                     false
            }
        

        @

        If i use the propertie-bindings correctly it works pretty well.
        In this way i can redefine the visibility after the qml file is processed.
        That makes the propertie-bindings way more powerful than the approach I
        was thinking of.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chrisadams
          wrote on last edited by
          #4

          You can pass initial property values as a parameter to Loader's setSource method. See http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-loader.html#setSource-method for more information.

          Component can take a similar parameter to its createObject and incubateObject methods: https://qt-project.org/doc/qt-5.0/qtqml/qml-qtquick2-component.html#createObject-method

          Cheers,
          Chris.

          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