Fix crash-on-exit in qmlscene.

Take control over NSWindow deletion to make sure
it's lifetime matches that of the QCocoaWindow.

Change-Id: Ia10006d814345356e6aebe7fa1f9a0e012535786
Reviewed-on: http://codereview.qt.nokia.com/2960
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@nokia.com>
bb10
Morten Sorvig 2011-08-15 13:50:22 +02:00 committed by Richard Moe Gustavsen
parent c9d1adb7fa
commit 4e6c4d50a5
3 changed files with 17 additions and 2 deletions

View File

@ -76,6 +76,7 @@ public:
void windowDidMove();
void windowDidResize();
void windowWillClose();
void setCurrentContext(QCocoaGLContext *context);
QCocoaGLContext *currentContext() const;

View File

@ -82,6 +82,12 @@ QCocoaWindow::QCocoaWindow(QWindow *tlw)
[m_nsWindow setDelegate:delegate];
[m_nsWindow setAcceptsMouseMovedEvents:YES];
// Prevent Cocoa from releasing the window on close. Qt
// handles the close event asynchronously and we want to
// make sure that m_nsWindow stays valid until the
// QCocoaWindow is deleted by Qt.
[m_nsWindow setReleasedWhenClosed : NO];
m_contentView = [[QNSView alloc] initWithQWindow:tlw];
if (tlw->surfaceType() == QWindow::OpenGLSurface) {
@ -99,7 +105,7 @@ QCocoaWindow::QCocoaWindow(QWindow *tlw)
QCocoaWindow::~QCocoaWindow()
{
[m_nsWindow release];
}
void QCocoaWindow::setGeometry(const QRect &rect)
@ -178,6 +184,12 @@ void QCocoaWindow::windowDidResize()
m_glContext->update();
}
void QCocoaWindow::windowWillClose()
{
QWindowSystemInterface::handleCloseEvent(window());
}
void QCocoaWindow::setCurrentContext(QCocoaGLContext *context)
{
m_glContext = context;

View File

@ -75,7 +75,9 @@
- (void)windowWillClose:(NSNotification *)notification
{
Q_UNUSED(notification);
QWindowSystemInterface::handleCloseEvent(m_cocoaWindow->window());
if (m_cocoaWindow) {
m_cocoaWindow->windowWillClose();
}
}
@end