Option-clicking the close-button on a window in macOS is a request to
batch-close all the windows. When this happens we get an event in through
the window that was clicked, which in turn results in AppKit calling
windowShouldClose: for each window. We respond to that by explicitly
closing each window (instead of just responding YES or NO), which
results in the window being released and deallocated. This causes
a crash when AppKit then follows up by closing each window after we
responded YES to windowShouldClose.
We work around this by keeping the window alive in the closest auto
release pool, which is typically at the level of the runloop. This
ensures that the window is alive for the duration of the logic that
AppKit has for batch-closing windows.
Fixes: QTBUG-92232
Pick-to: 6.2 6.1 5.15
Change-Id: I68b6138eb8325af0576b438ffa011137fec27926
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>