Search code examples
c++objective-ccocoansbutton

NSButton event handling in C++


I'm creating a thin layer of C++ on top of Cocoa widgets and there's a problem of handling NSButton events without ObjC object as a target.

Any ideas how could I use c++ class methods to handle button click?

For example:

[button setTarget:cppObj];
[button setAction:@(cppObjMethod:)]

The code above doesn't work, of course.


Solution

  • You would need to set the target and action to an Objective-c class / method which itself calls the C++ code.