From 0be8f59d725d4a5e79709487e3aac1d351a6c04c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 15 Jan 2018 12:15:39 +0100 Subject: [PATCH] macOS: Copy QNSWindowProtocol without referencing it by name The protocol may be namespaced, in which case the string lookup would fail, so we iterate the protocols of QNSWindow instead (of which there is only one, QNSWindowProtocol). Change-Id: Ic45752c9e3a40f5d42ec82c4287402a3d7a47b09 Reviewed-by: Gabriel de Dietrich --- src/plugins/platforms/cocoa/qnswindow.mm | 25 +++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/plugins/platforms/cocoa/qnswindow.mm b/src/plugins/platforms/cocoa/qnswindow.mm index e846fa043c2..cb13b7d1846 100644 --- a/src/plugins/platforms/cocoa/qnswindow.mm +++ b/src/plugins/platforms/cocoa/qnswindow.mm @@ -99,18 +99,25 @@ static bool isMouseEvent(NSEvent *ev) const Class windowClass = [self class]; const Class panelClass = [QNSPanel class]; - unsigned int methodDescriptionsCount; - objc_method_description *methods = protocol_copyMethodDescriptionList( - objc_getProtocol("QNSWindowProtocol"), NO, YES, &methodDescriptionsCount); + unsigned int protocolCount; + Protocol **protocols = class_copyProtocolList(windowClass, &protocolCount); + for (unsigned int i = 0; i < protocolCount; ++i) { + Protocol *protocol = protocols[i]; - for (unsigned int i = 0; i < methodDescriptionsCount; ++i) { - objc_method_description method = methods[i]; - class_addMethod(panelClass, method.name, - class_getMethodImplementation(windowClass, method.name), - method.types); + unsigned int methodDescriptionsCount; + objc_method_description *methods = protocol_copyMethodDescriptionList( + protocol, NO, YES, &methodDescriptionsCount); + + for (unsigned int j = 0; j < methodDescriptionsCount; ++j) { + objc_method_description method = methods[j]; + class_addMethod(panelClass, method.name, + class_getMethodImplementation(windowClass, method.name), + method.types); + } + free(methods); } - free(methods); + free(protocols); } - (QCocoaWindow *)platformWindow