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

Controlling a main.qml's Loader from a 'children' qml files



  • Hi,

    I am very new to Qt and QML. I have a main.qml file which has two views (kind of a splitview but manually made).

    In the first view, I load a qml filewhich contains a TabView . The contents of each tab would be loaded from other qml files. In each of these files I would like to have a button which would load the second view in the main.qml file.

    Is this approach possible? My main problem is how to make the qml files which are being viewed in the tabs to control the Loader in the main.qml.

    Thanks a lot!!!


  • Moderators

    @nazlab said in Controlling a main.qml's Loader from a 'children' qml files:

    Is this approach possible?

    Definitely!

    My main problem is how to make the qml files which are being viewed in the tabs to control the Loader in the main.qml.

    There are many ways to do it:

    • from your tabs, send a signal, which you can pick up in your main.qml and react by loading correct screen in your other view
    • define a Singleton, or a custom QObject added to root context property, which will contain certain signals - your tabs will fire those, and main.qml can react through a Connections {} component

    Hope it helps :-) I can get into more detail here, feel free to ask more detailed questions.



  • @sierdzio Thank you for your reply - I really appreciate it. It will take some time to digest your instructions as I am very new to qt and qml - I have to read about signals and how they work. However, just yesterday I got it working by creating a property of Loader in the main qml file which refers to the view I want to load other views and then I am calling that property in the qml file that is loaded from the tabs qml file.


Log in to reply