Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Doubt about deleting a child QObject

Doubt about deleting a child QObject

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.2k 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.
  • F Offline
    F Offline
    fluca1978
    wrote on last edited by
    #1

    Hi all,
    imagine I've got class A that inherits QObject and that creates an instance of class B, which inherits from QObject too, attaching himself as parent, so that B (instance) has A (instance) as parent. Now imagine that A performs an explicit delete on B (instance). What happens when A is deleted too? I mean, could the explicit deletion cause some sort of problems or the Qt is simply passing thru the no-more valid B pointer/reference? I imagine the latter, but it is just to be sure.

    1 Reply Last reply
    0
    • ZlatomirZ Offline
      ZlatomirZ Offline
      Zlatomir
      wrote on last edited by
      #2

      No, there is no problem in the situation you described, the child delete itself from it's parent's list of children.

      There is an issue if the child is allocated on stack and the parent gets deleted first: in this case parent calls delete on an address of a stack allocated object.

      //see "this":http://doc.qt.nokia.com/4.7-snapshot/objecttrees.html doc page

      https://forum.qt.io/category/41/romanian

      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