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. Child/Parent QObject Cleanup
Forum Updated to NodeBB v4.3 + New Features

Child/Parent QObject Cleanup

Scheduled Pinned Locked Moved General and Desktop
qobjectmemory managmensegfaultdeletion
2 Posts 2 Posters 1.9k Views 2 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.
  • C Offline
    C Offline
    cuddlykittens11
    wrote on last edited by
    #1

    I'm having some troubles with segfaults when I delete this one QObject subclass. None of the classes subclass eachother, the only subclass QObject. Here is the hierarchy:
    Let's say that I have objects, A, B and C. B & C are children of A:

    A

    • B
    • C

    But I also have some other objects (we'll call them X) that are the children of B. The problem is that the deconstructor for X requires a resource from B (a function call). But B is completely deleted before it's children (the X objects) are. Therefore when X is deleted I get a segfault.

    What can I do to fix this?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      ambershark
      wrote on last edited by ambershark
      #2

      How are you deleting your objects? Are you using delete or deleteLater? Seems odd this is happening since any delete on an object will delete all it's children before itself. At least with Qt parenting. If object X isn't a true child of B then that would cause your issue.

      I.e. if I have:

      QLabel *label = new QLabel();
      QLabel *child = new QLabel(label);
      
      delete label;
      // label should delete child by before it fully deconstructs.
      

      Also if you have real code or at the very least a backtrace I could help more.

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      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