Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Unload Dialog component through Loader
Qt 6.11 is out! See what's new in the release blog

Unload Dialog component through Loader

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 512 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MaxKazakovM Offline
    MaxKazakovM Offline
    MaxKazakov
    wrote on last edited by MaxKazakov
    #1

    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?
    Thanks!

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved