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

With the PMF connect syntax, slots are invoked on partially destroyed objects

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 6.3.0 Alpha
    • 5.2.0 Alpha
    • Core: Object Model
    • None
    • 0e72a846d379ba02ff80ecac2526640a05b872b6 (qt/qtbase/dev)

    Description

      This snippet shows a different behaviour of PMF connects vs. "old style": PMF incorrectly invoke the slot with this == QObject* (and not Object*), which means that f.i. accessing any member variable from that slot would result a in a crash.

      With "old style" the slot is not invoked.

      #include <QtCore>
      
      class Object : public QObject
      {
          Q_OBJECT
      public:
          Object()
          {
              connect(this, &QObject::destroyed, this, &Object::onDestroyed);
              // connect(this, SIGNAL(destroyed()), this, SLOT(onDestroyed()));
          }
      private slots:
          void onDestroyed()
          {
              qDebug() << Q_FUNC_INFO;
          }
      };
      
      int main(int argc, char **argv)
      {
          QCoreApplication app(argc, argv);
          Object o;
      }
      
      #include "main.moc"
      

      Attachments

        Issue Links

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

          Activity

            People

              Unassigned Unassigned
              peppe Giuseppe D'Angelo
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There is 1 open Gerrit change