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: 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 | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/plugins/platforms/cocoa/qnswindow.mm b/src/plugins/platforms/cocoa/qnswindow.mm index e846fa043c..cb13b7d184 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); - - 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 protocolCount; + Protocol **protocols = class_copyProtocolList(windowClass, &protocolCount); + for (unsigned int i = 0; i < protocolCount; ++i) { + Protocol *protocol = protocols[i]; + + 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 -- cgit v1.2.3