How to set sourceComponent (Loader) to load Component from another QML File ?



  • Hi, i'm looking for an Solution to Load a sourceComponent for a Loader from another QML File:
    First the QML File which holds the different Components:

    Item {
    id: sitesConfig_Item

    function sourceChooser(compInput){
        if (compInput === "tradPathButton"){
            return tradPath_Comp
        }
        else if (compInput === "configButton"){
            return config_Comp
        }
        else{
            return standard_Comp
        }
    }
    
    Component{
        id: tradPath_Comp
        Rectangle{
            anchors.fill: parent
            color: "red"
        }
    }
    Component{
        id: config_Comp
        Rectangle{
            anchors.fill: parent
            color: "grey"
        }
    }
    Component{
        id: standard_Comp
        Rectangle{
            anchors.fill: parent
            color: "black"
        }
    }
    

    }
    Second the QML File which includes the Loader:

    Rectangle{
        id: detail_Section_Information
        anchors.left: server.horizontalCenter
        anchors.right: section_rec.left
        anchors.leftMargin: layoutmargin8
        anchors.rightMargin: layoutmargin16
        //color: "red"
        y: parent.height
        height: (parent.height - (2 * layoutmargin16)) / 2
    
        Loader{
            id: detail_Section_Loader
            anchors.fill: parent
    
            sourceComponent: SitesConfig.sourceChooser(buttonHistorySection)
    
        }
    }
    

    I will always get this ERROR: qrc:/qml/Sites.qml:429: ReferenceError: SitesConfig is not defined
    so how can I fix it to Load the different Components?



  • Did you ever figure this out?



  • Expose your component through a property of file's root item.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.