Because Qt relies on a parent-child model to manage Qobject resources. It follows the composite + Chain-of-responsibility pattern, which is used from event management to memory management, drawing, file handling, etc…
Actually, trying to use a QObject in a shared\unique pointer is overengineering (99% of the time).
- You have to supply a custom deleter which will call deleteLater
- Your qobject with parents already have a reference in the parent object. So you know that a object is not leaked as long as the parent exist. When you need to get rid of it, you can call
deleteLaterdirectly. - Your QWidget without parent already have a reference in the Qapplication object. So same as point 2.
That said, you can still use RAII with Qt. For instance QPointer behaves as a weak reference on a QObject. I would use QPointer<QWidget> rather than QWidget*.
note: to not sound too fanboy, two words : Qt + valgrind.