qt: Fix shutdown when waitfor* cmds are called from RPC console
Summary: This is a backport of core#18452
Test Plan:
bitcoin-qt -server=1
In the RPC console, type waitforblockheight XXXXXX with XXXXXXX a future block height, then close the application. Make sure it does not hang.
Reviewers: #bitcoin_abc, majcosta
Reviewed By: #bitcoin_abc, majcosta
Differential Revision: https://reviews.bitcoinabc.org/D9260