I've got a logging interface that enables user to subclass a Logger and override the log() virtual function so customers can make their very own loggers. There's a supervisor that monitors all of the registered logging techniques (i.e. Console, syslog, Widget, etc.)

I have produced a QListWidget Logger that shows logs. Regrettably it's possessed through the logging manager and also, since it is a QObject, it is also a young child from the MainWindow. This leads to two objects attempting to remove it upon aplication close.

To begin with the QObjects->deleteChildren() will get known as also it removes it. Then your Loggin gmanager tries again and CRASH.

How do i prevent a particular QObject from being destroyed throughout deleteChildren()? Is the fact that an awful idea?

You cannot exclude a young child from deletion, and when you can, that'd be an awful idea. Within the QObject hierarchy, the kid is possessed through the parent. That's among the primary reasons from the parent-child relationship. I do not see why you need to desire a parent-child relationship with no deletion.


  1. Turn it into a child from the logging manager
  2. Don't provide a parent or gaurdian whatsoever and allow the logging manager remove it
  3. Don't provide a parent or gaurdian whatsoever and employ QSharedPointer/std::shared_ptr (the second in C++11), controlling it by utilizing QSharedPointer instances int mainwindow and logger.

Not understanding the code, I'd the mainwindow should not wreck havoc on the logger, and so i would slowly move the possession completely towards the manager.

Also, I do not visit a reason the typical Logger interface should inherit from QObject whatsoever, so I'd consider getting rid of that inheritance completely (which leaves the "possessed exclusively by Logging manager" and QSharedPointer options).