How to close a qml loaded by LOADER in its page.



  • hi guys,i got a problem.
    i set a main qml for main page,there are several buttons on it ,when clicking it ,a child page is loaded by loader element ,but how to close it. My plan is setting a BACK button on the child page,when clicking it ,the child page will be close .how to do it ?


  • Moderators

    Please read the "documentation":http://qt-project.org/doc/qt-5.1/qtquick/qml-qtquick2-loader.html#source-prop, it clearly states:
    [quote]To unload the currently loaded object, set this property to an empty string, or set sourceComponent to undefined. Setting source to a new URL will also cause the item created by the previous URL to be unloaded.[/quote]



  • [quote author="sierdzio" date="1377247986"]Please read the "documentation":http://qt-project.org/doc/qt-5.1/qtquick/qml-qtquick2-loader.html#source-prop, it clearly states:
    [quote]To unload the currently loaded object, set this property to an empty string, or set sourceComponent to undefined. Setting source to a new URL will also cause the item created by the previous URL to be unloaded.[/quote][/quote]
    YES , i read it yet .but the "unload“ which it said is to unload the source in the main page. now my child page is full of my screen.and i wanna click the BACK button on the child page to close it ...so i am confused:(


  • Moderators

    So, the Back button is a child of the page that is loaded inside the Loader?

    You can send a signal to your main view to notify it that the page needs to be closed. This is a clean and flexible solution, allowing you to react nicely in the main view, and it will be easy to extend later. Passing singals to and from Loaders is described in the documentation.

    Other possibility would be to clean "source" from inside your child page: you can get to Loader using parent-child hierarchy:
    @
    Loader {
    source: "kid.qml"
    }

    // kid:
    Item {
    id: root
    YourButton {
    onClicked: root.parent.source = ""; // or root.parent.parent.source = ""
    }
    }
    @

    I won't say it's a good solution, though.



  • [quote author="sierdzio" date="1377248767"]So, the Back button is a child of the page that is loaded inside the Loader?

    You can send a signal to your main view to notify it that the page needs to be closed. This is a clean and flexible solution, allowing you to react nicely in the main view, and it will be easy to extend later. Passing singals to and from Loaders is described in the documentation.

    Other possibility would be to clean "source" from inside your child page: you can get to Loader using parent-child hierarchy:
    @
    Loader {
    source: "kid.qml"
    }

    // kid:
    Item {
    id: root
    YourButton {
    onClicked: root.parent.source = ""; // or root.parent.parent.source = ""
    }
    }
    @

    I won't say it's a good solution, though.[/quote]
    i'll try it ...and really very thank u because u r so enthusiastic! and wanna communicate more :)


Log in to reply
 

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