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. How to set sourceComponent (Loader) to load Component from another QML File ?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved QML and Qt Quick
loader
3 Posts 2 Posters 1.8k 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.
  • David_001D Offline
    David_001D Offline
    David_001
    wrote on last edited by David_001
    #1

    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?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bmurphy
      wrote on last edited by
      #2

      Did you ever figure this out?

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bmurphy
        wrote on last edited by
        #3

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

        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