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

deleteLater() never delivered if triggered by a sendEvent()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4: Low
    • 6.7
    • 5.14.1
    • Core: Event loop
    • None
    • All

    Description

      In the following snippet ~MyObject dtor is never run.

      #include <QDebug>
      #include <QCoreApplication>
      
      class MyObject : public QObject
      {
      public:
          MyObject() {
              qDebug() << "CTOR" << this;
          }
      
          ~MyObject() {
              qDebug() << "DTOR" << this;
          }
      
          bool event(QEvent *ev) override
          {
              if (ev->type() == QEvent::User) {
                  qDebug() << "Got a user event, will deleteLater()";
                  deleteLater();
              }
      
              return QObject::event(ev);
          }
      };
      
      int main(int a, char **b)
      {
          QCoreApplication app(a, b);
      
          auto obj = new MyObject();
      
          QEvent ev(QEvent::User);
          QCoreApplication::sendEvent(obj, &ev);
      
          return app.exec();
      }
      
      // Output:
      
      $ CTOR QObject(0x56427a6211b0)
      $ Got a user event, will deleteLater()
      
      

      Attachments

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

        Activity

          People

            vestbo Tor Arne Vestbø
            iamsergio Sergio Martins
            Votes:
            1 Vote for this issue
            Watchers:
            11 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes