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

QStringList inherits from base class with non-virtual destructor

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 3.x, 4.0.0, 4.0.1, 4.1.0, 4.1.1, 4.1.2, 4.1.3, 4.1.4, 4.1.5, 4.2.0, 4.2.1, 4.2.2, 4.2.3, 4.3.0, 4.3.1, 4.3.2, 4.3.3, 4.3.4, 4.3.5, 4.4.0, 4.4.1, 4.4.2, 4.4.3, 4.5.0, 4.5.1, 4.5.2, 4.5.3, 4.6.0, 4.6.1, 4.6.2
    • None

    Description

      The QStringList class inherits from QValueList<QString> (or from QList<QString> on newer versions) by public inheritance. This makes it possible to use QStringList objects polymorphically where QValueList<QString> pointers are expected:
      QValueList<QString>* pList = new QStringList();
      delete pList;

      However, as QValueList<QString> does not have virtual destructor, the above code is undefined behavior and leads at least to slicing. I do not have the source code of QList available at the moment, but the online docs do not mention a virtual destructor there either.

      A better approach would be specialize the QValueList (or QList) template for QString or just define the methods in QStringList as ordinary non-member functions receiving iterators or a Container<QString> object, e.g.
      template
      <
      template<typename> class Container
      >
      void indexOf(Container<QString> const&, const QRegExp & rx, int from = 0 )
      {
      ...
      }

      Attachments

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

        Activity

          People

            stormols Marius Storm-Olsen
            jensa Jens Auer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes