Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-48744

Create something like list of QScopedPointers (QScopedList or QScopedPointerList))

    XMLWordPrintable

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).

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            bartekbl Bartosz Błaszkiewicz
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes