flush replies when entering an eventloop

avoids possible hangs when the GUI eventloop prevents queued replies from being sent
Merge pull request #5077 from minrk/qt-hmm

Flush replies when entering an eventloop. This avoids possible hangs when the GUI eventloop prevents queued replies from being sent.

Closes #4997.