fix random hangs in the event loop
Calling QCoreApplication::processEvents with QEventLoop::WaitForMoreEvents
can sometimes cause it to hang waiting for more events. Also, calling
QCoreApplication::sendPostedEvents is recommended for the deleteLater()
calls to be processed correctly [1] so that memory leaks do not occur.
Thanks to @bgra and @DanielCeregatti, fixes #2254 and #1977 and #1706
and possibly many other issues.
[1] http://doc.qt.io/qt-4.8/qcoreapplication.html#processEvents