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. Issues with using object.destroy()
Qt 6.11 is out! See what's new in the release blog

Issues with using object.destroy()

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 2.3k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hello,

    I am trying to implement a Reset button such that when the user clicks 'Reset', I dynamically create a QML file using the method shown here:

    "Dynamic Object Management":http://qt-project.org/doc/qt-4.8/qdeclarativedynamicobjects.html

    This object I make is a simple confirmation box that says: "Are you sure?" and has two buttons Yes or No.
    The Yes Button works fine, but when I click No, I want to remove the box and so I run container.destroy(). The following is the QML file I create for the confirmation box

    @import QtQuick 2.0
    import QtQuick.Controls 1.0
    import "../SetUp/SetUp.js" as SetUp

    Rectangle {
    id: container
    width: parent.width0.1; height: parent.height0.1
    anchors.centerIn: parent
    color: "black"; radius: 5;
    Column {
    anchors.centerIn: parent
    id: col
    spacing: 5
    Item {
    width: ask.width; height: ask.height
    Text {
    id: ask
    text: "Are you sure?"
    color: "white"
    font.pixelSize: container.height*0.25
    }
    }
    Item {
    width: row.width; height: row.height
    Row {
    id: row
    spacing: 2
    Button {
    text: "Yes"
    onClicked: {
    SetUp.pageNum = 1;
    SetUp.menuOn = 0;
    SetUp.createSpriteObjects("SetUp.qml")

                    }
                }
                Button {
                    text: "No"
                    onClicked: {
                        SetUp.menuOn = 0;
                        container.destroy()
                    }
                }
            }
        }
    }
    

    }
    @

    After selecting No, I can't click any other buttons on my screen to enable other menu options. I can't even click the Reset Button anymore....
    Can someone explain why this happens and if I can fix it?

    1 Reply Last reply
    0
    • O Offline
      O Offline
      onek24
      wrote on last edited by
      #2

      Does the console output something? Because since i remember one component can't destroy itself.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        yes it does, if i change the No button to:
        @Button {
        text: "No"
        onClicked: {
        SetUp.menuOn = 0;
        container.destroy()
        console.log("die")
        }
        }@

        the console outputs 'die' and the object is destroyed, but I cant click the reset button which created the object the first time

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          also, the reset button which creates this confirmation box is the only thing I can't click to elicit a 'console.log("fsdafa")' line after I click 'No' and destroy the box. The other menu options still print to the console

          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