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. how to recall a destroyed element in Qml?
Qt 6.11 is out! See what's new in the release blog

how to recall a destroyed element in Qml?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 Posters 794 Views 1 Watching
  • 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.
  • S Offline
    S Offline
    Sanyam
    wrote on last edited by
    #1

    here is a button which will destroy an item upon clicked but when the item is recalled it's showing me a blank page. is there any method to recall that item again after destroying?

        Button{
            id: backButton5
            width: menuRow5.width*(59/1920)
            height: menuRow5.height
            onClicked: {
                mappingWidgetId.visible=!mappingWidgetId.visible
                treebuttonUnmappedIn.destroy()
            }
    
        UnmappedTreeViewButtonPressed {
            id: treebuttonUnmappedIn
            anchors.left: parent.left
            anchors.top: parent.top
        }
    
                RoundButton {
                    id:viewUnmappedSettingsButton
                    height:mappingWidget.height*(33/1200)
                    width:mappingWidget.width*(265/1920)
                    onClicked: {
                        treebuttonUnmappedIn.visible = true
                    }}
    

    UnmappedTreeViewButtonPressed.qml

    import QtQuick 2.15
    import QtQuick.Window 2.15
    import QtQuick.Controls 2.15
    import QtQuick.Dialogs 1.3
    import QtQuick.Layouts 1.15
    Rectangle{
         id: unmappedTreeId
         height:1000
         width: 1000
         anchors.leftMargin:350
    
         anchors.topMargin: 200
         color: "white"
         visible: false
    }
    
    
    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      @Sanyam said in how to recall a destroyed element in Qml?:

      treebuttonUnmappedIn.destroy()

      I cannot even find where "destroy" function/signal is documented. Anything created by QML is managed by QML. If you want to hide something then make it invisible by setting visible to false. If you want to create and destroy things then use Loaders, Repeaters or various Views and a model. Stay far away from using hands on memory management type stuff in QML. I would consider that an anti-pattern in QML.

      C++ is a perfectly valid school of magic.

      JoeCFDJ 1 Reply Last reply
      0
      • fcarneyF fcarney

        @Sanyam said in how to recall a destroyed element in Qml?:

        treebuttonUnmappedIn.destroy()

        I cannot even find where "destroy" function/signal is documented. Anything created by QML is managed by QML. If you want to hide something then make it invisible by setting visible to false. If you want to create and destroy things then use Loaders, Repeaters or various Views and a model. Stay far away from using hands on memory management type stuff in QML. I would consider that an anti-pattern in QML.

        JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by JoeCFD
        #3

        @fcarney https://doc.qt.io/qt-6/qtqml-javascript-dynamicobjectcreation.html destroy() does exist.
        I would use loader to recreate treebuttonUnmappedIn when it is recalled.

        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