Unload Dialog component through Loader

  • Hello.
    I use Loader to load my component based on Dialog object.

    Loader {
            id: dialogLoader
            anchors.centerIn: parent
             onLoaded: {
                 item.modality = Qt.WindowModal
                 item.visible = true

    I load component using "source" property (set qml file) like:

     function showModalWindow(qmlFile) {
            dialogLoader.source = qmlFile;
            if (dialogLoader.item == null) {
                console.log("Error creating object");

    When dialog window closed I would like unload my component. So, I need to set into Loader source property an empty string.
    I decided if dialog window visible property go to false I should unload it. I implemented the Connections object and connected to onVisibleChanged signal handler:

     Connections {
            target: dialogLoader.item
             onVisibleChanged: {
                if (!dialogLoader.item.visible){
                   dialogLoader.source = "";

    But when I do some action that hide my dialog window (press OK, Cancel or cross button) this handler does not work.

    What is the best way to implement logic I want?

Log in to reply

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