cocoa - objective c++ accessing an NSSlider from c++ callback -


appcontroller.h

@interface appcontroller : nsobject {  }  @property (retain) iboutlet nsslider * myslider;  void setmyslider (nsslider *ns);// c function 

appcontroller.m

@implementation appcontroller  int myamount=0; @synthesize myslider;   void setmyslider(nsslider *myslider){      [ns setintvalue:10]; //ok     ns.intvalue =myamount;//ok }  mycallbackfunction(double delta,std::vector<unsigned char>*mydata,void *userdata){  myamount=50;  nslog(@"%i", myamount); // ok display value of myamount  // should move slider value of amount calling following c function:  changeslidervelocity(myslider);// error message myslider not declared in scope  } 

no.

in case, though mycallbackfunction() placed between @implementation , @end not within class scope of appcontroller. int myamount static class-ish member (i have no idea scope is. global??) because defined in implementation file, not part of object appcontroller.

no guarantees work, give shot. assumes there ever 1 (one) instance of appcontroller. read more on singletons in obj-c/c++.

@implementation appcontroller  static appcontroller *sharedappinstance = nil;  - (void) init {   // ... whatever other code have   if (sharedappinstance == nil)       sharedappcontroller = self; //error message sharedappcontroller not declared in //this scope. replaced line sharedappcontroller = self; by:         sharedappinstance= self;  }  mycallbackfunction(double delta,std::vector<unsigned char>*mydata,void *userdata){  changeslidervelocity([[appcontroller sharedappinstance] myslider]); // replace line make work: changeslidervelocity([sharedappinstance myslider]);//ok work.  }  @end 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -