Send Signals between different Qml Objects



  • Hello,
    I have some items define in different QML files and i load them dynamically base on user option in my main qml. I want when one of these items is clicked to load a specific item in my main QML file.
    As i was searching for a solution for this i tried Signals but i can only make it work if items are defined in main QML. I think the problem lies in the way i initialize my QML items(i dont know if there is otherway around)

    The code below is how i choose which Grid to load (the items are initialized there) base on user option

     function getModelFile()
        {
            if (choice === "1") return "Fourby4Mesh4VCs.qml";
            else if (choice === "2") return "Threeby3Mesh4Vcs.qml";
    
    
        }
    Loader{
                    width:rowLayout.width*0.55
                    height: rowLayout.width*0.55
                    anchors.left: topologyLayout.left
                    anchors.top: topologyLayout.top
                    sourceComponent: none.none
                    id:loadTopology
                    source:getModelFile()
    
                }
    


  • @nnicou Your code tells nothing, I can't even see how it's related to your question. If you use Loader, did you follow "Receiving signals from loaded objects" in Loader doc?



  • It is about signals between different objects. You are loading QML file through loader. This creates new object that representing that qml file. You can access the object creation loader through id:loadTopology.item.

    You can define connections like this for the signals which are emitted from the qml files which are loaded through loader.

    Connections {
    target : loadTopology.item
    on<Signal>:{

    }
    }

    Please note it is not about signals between qml files. QML files are components. You are creating the objects from these components. Signals/slots communication need to happened between objects.



  • Sorry i have a edited my post but i am not sure if have explained correct what i am trying to do

    I will add a photo that it may explained better what i ma trying to do
    https://drive.google.com/open?id=0B1zHpsqEO9qBekZUYmZEUndDaWM



  • @dheerendra Your post helped me alot and thank you for the explanation.!


Log in to reply
 

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