FIX: re-order qt eventloop hook a bit
FIX: re-order qt eventloop hook a bit

try to reduce race conditions by:

 - connect the exit callback before enabling the notifier (this might
   not matter)
 - only bother starting the event loop if the input is not ready.

closes #10201

ipython/ipython,ipython/ipython