How to set sourceComponent (Loader) to load Component from another QML File ?
Solved
QML and Qt Quick
-
wrote on 11 Aug 2016, 11:19 last edited by David_001 8 Nov 2016, 11:21
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_Itemfunction 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? -
wrote on 30 Mar 2017, 22:15 last edited by
Did you ever figure this out?
-
wrote on 30 Mar 2017, 22:26 last edited by
Expose your component through a property of file's root item.