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
The dtor of the QObject in question is called right after the deleteLater, when the main loop spins the next time.
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)
it's thread affinity: QThread(0x922c488)
adding idle callback QThread(0x922c488)
And after 3 s: