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

When deleteLater() is called from QEvent destructor, object won't be deleted until the event loop exits

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.5.1
    • Core: Event loop
    • None

    Description

      When deleteLater() is called from the QEvent destructor (of an event delivered to the main loop), the object won't be delivered until the event loop exits.

      The bug exists at least until Qt 5.5.1 (but probably also in current versions).

      The attached test case should print:

      X::X() 
      X::~X() 
      Calling o->deleteLater() 
      Object is being destroyed 
      timer expires, objExists = false 
      

      but instead it prints:

      X::X() 
      X::~X() 
      Calling o->deleteLater() 
      timer expires, objExists = true 
      object has not been destroyed 
      Object is being destroyed 
      

      Note that X::~X() is executed from the destructor for the event which is used to deliver the queued signal from Obj::fooSig to Obj::fooSlot. This destructor is called from QCoreApplicationPrivate::sendPostedEvents when the QScopedPointer is destroyed, and not from QCoreApplication::sendEvent/QCoreApplication::notifyInternal like almost all other user code is. As far as I can see this means that the loop level counter is not incremented and the QDeferredDeleteEvent records a too low loop level.

      Attachments

        1. QtDeleteLaterEventDtor570.cpp
          2 kB
          Steffen Kieß
        2. QtDeleteLaterEventDtor.cpp
          1 kB
          Steffen Kieß
        3. QtDeleteLaterEventDtor.hpp
          0.3 kB
          Steffen Kieß
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            steffen-kiess Steffen Kieß
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes