Use QEventLoop for modal windows.

According to the Qt forums, you can call qApp->exec() only once per application, otherwise weird things occur. In particular 100% CPU usage.

Fixes #11666