From abde2a59c603899c80e67bb5e7f892d554ff72fd Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Mon, 22 Sep 2014 14:55:04 +0200 Subject: Cocoa: Properly remove content view from its superview in setNSWindow() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -[NSWindow setContentView:] doesn't make assupmtions about where that view comes from, and just attaches it to the window. We need to make sure we detach it from its previous window by calling -[NSView removeFromSuperview], or the previous NSWindow may keep references to the view. This can be an issue if the view is deleted right after. Task-number: QTBUG-39628 Change-Id: I152dedcb64ac044d8ca290c9996b388809e2477b Reviewed-by: Timur Pocheptsov Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoawindow.mm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 19d0f7a987..96c882887e 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1477,7 +1477,11 @@ void QCocoaWindow::setNSWindow(QCocoaNSWindow *window) { if (window.contentView != m_contentView) { [m_contentView setPostsFrameChangedNotifications: NO]; + [m_contentView retain]; + if (m_contentView.superview) // m_contentView comes from another NSWindow + [m_contentView removeFromSuperview]; [window setContentView:m_contentView]; + [m_contentView release]; [m_contentView setPostsFrameChangedNotifications: YES]; } } -- cgit v1.2.3