Improved handling of quit requests

There was no proper call to close the QCoreApplication so secondary
windows would remain open after an attempting to quit.