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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 4.7.3, 5.4.0
    • Fix Version/s: 5.8.0 Alpha
    • Component/s: Core: Event loop
    • Labels:
      None

      Description

      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

        Attachments

        1. glib_signals_to_qt_slots_thread.tar.gz
          2 kB
        2. glib_signals_to_qt_slots.tar.gz
          2 kB
        3. main.cpp
          1 kB
        4. qt_deletelater.pro
          0.4 kB

          Issue Links

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

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes