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

Help voiding crashes due to use of qDeleteAll and QObject:destroyed together

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.12.0
    • None
    • Linux

    • All

    Description

      When using qDeleteAll on list of classe of QObject there might be a pitfall when using QObject:destroyed, if user want to delete object from same list as it will cause the application to crash.

      tst_qdeletall.zip illustrates a bad use of qDeleteAll, where it will crash.

      I suggested making qDeleteAll more safe like this:

      template <typename ForwardIterator>
      Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
      {
          while (begin != end) {
              auto object = *begin;
              ++begin;
              delete object;
          }
      }
      
      template <typename Container>
      inline void qDeleteAll(const Container &c)
      {
          qDeleteAll(c.begin(), c.end());
      }
      

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            paletteguy Karsten Sperling Opdal
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes