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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 5.2.0 Alpha
    • Fix Version/s: 6.3.0 Alpha
    • Component/s: Core: Object Model
    • Labels:
      None
    • Commits:
      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

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

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes