summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2018-02-16 15:35:32 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2018-02-28 17:06:41 +0000
commit5d365b96b9a9d8585a0be5cc1c2376b7b2f27101 (patch)
tree6934a160d98972629805fa5e7074427ec55512d4
parentdf3da2c1d16ad9faa749f9bf0a778a8956c48616 (diff)
macOS: Warn the user when KVO-observing QCocoaNSWindow
We recreate the window of our QNSView in various situation such as changing the styleMask, which results in either a new QNSwindow or QNSpanel being set as the window of the view. KVO-observing the window property of the view will fail we then have a new window instance, and will crash when trying to remove the observer from the new window. Unfortunately catching the NSRangeException that happens when removing an observer from a 'switched' window is not possible, so the user is left with: Terminating app due to uncaught exception 'NSRangeException', reason: Cannot remove an observer <Foo 0xabc> for the key path "bar" from <QNSPanel 0xdef> because it is not registered as an observer. Change-Id: Ib2adbb99f19303a054fb1eb65e959aecd32b1162 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index 17ded6ce59..f9c676a5b0 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -1262,6 +1262,11 @@ void QCocoaWindow::recreateWindowIfNeeded()
if ((isContentView() && !shouldBeContentView) || (recreateReason & PanelChanged)) {
if (m_nsWindow) {
qCDebug(lcQpaCocoaWindow) << "Getting rid of existing window" << m_nsWindow;
+ if (m_nsWindow.observationInfo) {
+ qCCritical(lcQpaCocoaWindow) << m_nsWindow << "has active key-value observers (KVO)!"
+ << "These will stop working now that the window is recreated, and will result in exceptions"
+ << "when the observers are removed. Break in QCocoaWindow::recreateWindowIfNeeded to debug.";
+ }
[m_nsWindow closeAndRelease];
if (isContentView()) {
// We explicitly disassociate m_view from the window's contentView,