implements application closing logic in qt gui