IBoutlets out of scope in c functions?
IBoutlets out of scope in c functions?
- Subject: IBoutlets out of scope in c functions?
- From: "Mike Lehmann" <email@hidden>
- Date: Fri, 10 Mar 2006 06:03:56 -0700
hi all,
I'm way noob at cocoa but have relatively thick skin, so feel free to
comment on anything you think I'm doing wrong aside from the question
at hand :)
I'm learning/using cocoa as a gui front end for a substantial c++
peer-to-peer SIP project. The c++ engine needs to be able to send
events to the gui asynchonously, but obviously (to me, anyway) can't
send objective-c messages without being compiled as objective-c++. So
I thought the way to handle this was to write c functions within the
objective-c code, and pass pointers to those functions to an event
handler class within the c++ code. The c++ code fires, my code gets
executed, and everyone wins, in principle...
I've had no problems getting all the connections to work, and am able
to see the messages generated by the c++ class, as well as convert the
generated info to an NSString. This NSString in turn is quite happy
to be displayed in an NSLog, but balks at being used in an NSTextView.
More specificly, if I try to pass a message to my "display screen"
(NSTextView), I am informed that the NSTextview is out of scope. I
don't know if I've made a small error and the idea is ok, or if I've
made a large error and need to find a better way (pipes?) for the
engine to talk to the gui.
Here is the relevant code....
=============
(from Controller.h)
=============
@interface Controller : NSObject
{
IBOutlet id bellMessage;
IBOutlet id conversation; // This is the IBOutlet in question
IBOutlet id watsonMessage;
IBOutlet id watsonStatus;
}
- (IBAction)sendBellMessage:(id)sender;
- (IBAction)sendWatsonChatter:(id)sender;
- (IBAction)sendWatsonMessage:(id)sender;
- (IBAction)sendWatsonStatus:(id)sender;
=============
(from Controller.M)
=============
// This is the function whose address is passed to the c++ class
void printChatter( const string &inString )
{
const char *cString = inString.c_str();
NSString *chatterString =
[NSString stringWithCString:cString];
NSLog(@"chatter from c++ class is: %@", chatterString);
// Everything up to here works like a charm
// If I build with this line uncommented, I receive the following error:
// 'conversation was not declared in this scope
unsigned int loc = [[conversation textStorage] length];
}
// This is my "feeder" function. In this "toy" version, a certain button on my
// cocoa gui causes this method to run. This method in turn instantiates a
// c++ object that will invoke the c function implemented above.
// As a debugging step I first send some "chatter" of my own before asking the
// c++ object to generate some.
- (IBAction)sendWatsonChatter:(id)sender
{
// My own chatter
NSString *newString = @"(W) I <3 teh web!\n";
unsigned int loc = [[conversation textStorage] length];
unsigned int len = 0;
[conversation
replaceCharactersInRange:NSMakeRange(loc, len)
withString:newString];
// c++ chatter
// FYI PF is a typedef for the "pointer to function" syntax
PF myFuncPtr = printChatter;
Chatter myChatter( myFuncPtr );
myChatter.iterate( 2 );
}
I apologize for the novel-length of this question, but wanted to err
on the side of too much, rather than too little, information. Any
help or suggestions are much appreciated.
thanks,
Mike Lehmann
http://www.sipeerior.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden