Important: Please read the Qt Code of Conduct -

Passing Data from QML to QML via Loader

  • 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.

  • 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.

  • 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)


    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.

  • You can pass initial property values as a parameter to Loader's setSource method. See for more information.

    Component can take a similar parameter to its createObject and incubateObject methods:


Log in to reply