Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Destroy qml object
Qt 6.12 LTS is out! See what's new in the release blog

Destroy qml object

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 4.0k 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

    How can i instantly delete dynamically created objects?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chrisadams
      wrote on last edited by
      #2

      Not instantly. You can invoke .destroy() on them, but that will merely queue them for deletion at a safe time (basically a deleteLater() from C++ land).

      Technically, you could write your own function which gets exposed to QML via Q_INVOKABLE etc, something like: Q_INVOKABLE void deleteImmediatelyAndProbablyCrash(QObject *someObject) { delete someObject; } but it's a bad idea.

      Cheers,
      Chris.

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

        I want to empty all children of grid before adding next set of children. But .destroy() only delete the first set children after new children are added.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chrisadams
          wrote on last edited by
          #4

          If you're talking about their visual appearance, why not set visible to false? That should stop them from taking up any space in the visual layout.

          But that's a separate issue to the object lifetimes. Why is it important that you delete some before creating others? Are you on a really tight memory budget, or something?

          Cheers,
          Chris.

          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
          • Unsolved