Qt closeevent fixes for  v1.2.x

This rolls up PR #1678 and PR #1683 cherry-picked on to v1.2.x.

For future reference, is there a better way to do something like this than cherry-picking each commit by hand? (my naive attempt to re-base blew up as it tried to move _all_ of master over).