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

Using QAssociativeIterable with a pointer as the container value corrupts the container

    XMLWordPrintable

    Details

    • Commits:
      bedf0367ac580a2e73712be2f4207bb6af9f0226

      Description

      The following code crashes consistently, changing the QObject * to a QString, or int, works perfectly, and it's not like that it deletes the pointer because the qDebug() after the code shows that the keys are either empty or pointing to random memory, and the "this" destructor is not caller either.

          QMap<QString, QObject *> mapping;
            mapping.insert("Seven", this);
            mapping.insert("Eleven", this);
            mapping.insert("Forty", this);
            qDebug() << mapping;
      
            QVariant variant = QVariant::fromValue(mapping);
      
           if (variant.canConvert<QVariantHash>()) {
               QAssociativeIterable iterable = variant.value<QAssociativeIterable>();
      
               // Can use iterators:
               QAssociativeIterable::const_iterator it = iterable.begin();
               const QAssociativeIterable::const_iterator end = iterable.end();
               for ( ; it != end; ++it) {
                   qDebug() << it.key()
                            << it.value();
               }
           }
           qDebug() << mapping;
      

        Attachments

        For Gerrit Dashboard: QTBUG-52246
        # Subject Branch Project Status CR V

          Activity

            People

            Assignee:
            steveire Stephen Kelly (Personal)
            Reporter:
            dantti Daniel Nicoletti
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes