Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Composing QML objects from different files: Accessing functions in parent



  • Hi,

    Lets assume I have a file Plot.qml and files PlotOverlayA.qml and PlotOverlayB.qml. I don't want to move PlotOverlayA into Plot.qml as it is only needed in some circumstances and my Plot.qml file would get quite bloated if I moved every component there.

    If I use my plot component, I would like to do something like

    Plot {
    
        PlotOverlayA {
    
        }
    
    }
    

    Plot.qml has a signal update and I would like to connect to this signal in PlotOverlayA.qml. If I receive this signal in PlotOverlayA, it should bexecute a function defined in Plot.qml (like getXCoordinates). However, I don't know how I can access the functions of Plot.qml.



  • Maybe I don't understand, if you connect signal update in Plot with function in in the same file it doesn't enough? You can also connect signal from Plot with something in PlotOverlayA using id property



  • What I am trying to do is to create a flexible and reusable plot component. I would like to keep the interface (the properties of Plot.qml) small, and hope that this is achievable via "extending" the Plot component e.g. with a PlotOverlay as shown above. So PlotOverlay should be seen as tightliy coupled to plot. I will try with the id



  • If I receive this signal in PlotOverlayA, it should bexecute a function defined in Plot.qml

    Do you mean "emit the signal" in here?

    are the PlotOverlayA only children item of Plot?


Log in to reply