Please nominate your Qt Champions for 2021!

Call main.qml function from another qml

  • Hello,

    I have a function in my main.qml I would like to know how can I access it from another qml file.

    For example :
    main.qml contains funct1()
    in my foo.qml I want to do something like main.funct1()

    Is this possible ?

    Thank you in advance

  • Well everything should be "contained" in the main file any way, so each element of the other files should have as parent the main "Window" or "ApplicationWindow", so unless your app has a structure that deviates from the "standard" you could just call funct1() as long as you define it at the top of your main.qml.

  • Ok I understand now ! My problem was because I did not put the function at the top of the main.qml
    Thanks for your help

Log in to reply