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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P4: Low
    • Resolution: Unresolved
    • Affects Version/s: 5.14.1
    • Fix Version/s: None
    • Component/s: Core: Event loop
    • Labels:
      None
    • Platform/s:
      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

            Assignee:
            Unassigned Unassigned
            Reporter:
            iamsergio Sergio Martins
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes