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

QObject::deleteLater called from a function scheduled by g_idle_add --> QObject won't get deleted the next time the main loop spins

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P2: Important P2: Important
    • 5.8.0 Alpha
    • 4.7.3, 5.4.0
    • Core: Event loop
    • None

      The attached source code
      1. schedules a function to be called with g_idle_add
      2. when the function is called, calls deleteLater on a QObject
      3. spins the main loop (QCoreApplication::exec()) the rest of the time

      Expected outcome:
      The dtor of the QObject in question is called right after the deleteLater, when the main loop spins the next time.

      Actual outcome:
      The dtor of the QObject in question is called only after QCoreApplication::quit() has been called.

      The program prints out:
      main thread is QThread(0x922c488)
      created Sender(0x922f918)
      it's thread affinity: QThread(0x922c488)
      adding idle callback QThread(0x922c488)
      calling QCoreApplication::exec
      callback QThread(0x922c488)

      And after 3 s:
      destroyed Sender(0x922f918)
      QCoreApplication::exec returned

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

            paangele Paolo Angelelli
            marja Marja Hassinen
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes