[qtdeclarative] Fix deadlock when QQmlEngine is destroyed during compilation.

Before blocking to wait for the thread to finish ensure the thread
itself is not waiting for the main thread to complete some action
otherwise both threads will be waiting on the same wait condition that
neither is able to wake.  Likewise ensure the shutdown action is
processed if the last scheduled event is currently being processed.
Merge pull request #49 from adenexter/qqmlthread

[qtdeclarative] Fix deadlock when QQmlEngine is destroyed during compila...