Details
-
Suggestion
-
Resolution: Out of scope
-
Not Evaluated
-
None
-
None
-
None
-
all
Description
I am aware of classes: QScopedPointer and QScopedArrayPointer. However they have significant drawback: QScopedPointer manages only a single object, while QScopedArrayPointer requires you to create all objects at the same time. What if I am creating them one by one and somewhere in the middle I get an error?
I usually surround such code with try/catch and implement clean-up manually.
I could create a dummy QObject and parent new objects to it, but in only works for QObjects. Plus it frees me from manual clean-up, but stiil requires me to "unparent" them in the end.
With C++11 "move" syntax I think it would be possible to create QList<QSopedPointer<...>> which would satisfy me.
The most straightforward solution is IMHO to create a class that behaves like QList, only it can only hold pointers and its destructor deletes whatever those pointer point at (unless they are NULL of course).