访问数据从c++函数到UITextView控制器
Accessing data from C++ function into UITextView controller
我有一个问题。我需要分配值到UITextView控制器在我的iPad应用程序从一个c++函数。c++函数返回一个字符串,我可以在输出窗口看到输出。我用。mm文件合并了c++和XCode objective C。现在,我需要从c++函数中获取值,并将它们添加到uitextfield中。
比如说。我的c++函数是这样的:. cpp文件
void *consumer (void* data)
{
SyncBuffThang<GLOBAL_BUFF_LEN,GLOBAL_BUFFS>* cc =(SyncBuffThang<GLOBAL_BUFF_LEN,GLOBAL_BUFFS>*) data;
affinity("consumer", cons);
for (int ii=0; ii<100; ii++)
{
unsigned char c = cc->get();
cc->res = c;
myVar = c;
cerr << "Consumer Get" << myVar << endl;
f +=c;
}
cerr << "Leaving consumer in method cons" << f << endl;
return 0;
}
int PC9::RunPC()
{
SyncBuffThang<GLOBAL_BUFF_LEN, GLOBAL_BUFFS> pc;
pthread_t p, c;
pthread_create(&p, 0, producer, &pc);
pthread_create(&c, 0, consumer, &pc);
pthread_join(p, 0);
pthread_join(c,0);
}
下面是.mm文件代码。
#import "PC.h"
#import "PC9.h"
#import "GV.h"
@implementation PC
-(void)callFunctionPC
{
PC9 * myCPlusPlusObj; //A C++ object
myCPlusPlusObj=new PC9();
myCPlusPlusObj-> RunPC();
}
@end
在上面的函数中,我可以打印myVar,但是,我不知道如何从我的iPad应用程序访问它或在UITextFile上查看它。
朋友们,我真的很感激你们的帮助。
提前感谢。
- t
这就是我一直在等待的答案!!
HelloWorld.h
#ifndef __Demo1__HelloWorld__
#define __Demo1__HelloWorld__
#include <iostream>
#endif
class HelloWorld {
public:
std::string Mtd_HelloWorld();
};
HelloWorld.cpp
#include "HelloWorld.h"
std::string HelloWorld::Mtd_HelloWorld()
{
std::string output;
output = "This is from C++";
return output;
}
HelloWorldM.h
#import <Foundation/Foundation.h>
@interface HelloWorld_M : NSObject
-(NSString *)CallCPP;
-(UIView *)CreateTextView:(NSString *)input;
@end
HelloWorld.mm
#import "PCViewController.h"
#include "HelloWorld.h"
#include "HelloWorld_M.h"
@implementation HelloWorld_M
-(NSString *)CallCPP
{
HelloWorld * myCPlusPlusObj; //A C++ object
myCPlusPlusObj=new HelloWorld();
std::string res = myCPlusPlusObj-> Mtd_HelloWorld();
NSString *result = [NSString stringWithCString:res.c_str()
encoding:[NSString defaultCStringEncoding]];
return result;
}
-(UIView *)CreateTextView:(NSString *)input
{
UITextView *myTextView = [[UITextView alloc] initWithFrame: CGRectMake (0.0,0.0,320.0,200.0)];
myTextView.text = input;
return myTextView;
}
@end
PCViewController.h
#import <UIKit/UIKit.h>
#import "HelloWorld_M.h"
@interface PCViewController : UIViewController
{
HelloWorld_M *objHelloWorld;
}
- (IBAction)RunHelloWorld:(id)sender;
@end
PCViewController.m
#import "PCViewController.h"
@interface PCViewController ()
@end
@implementation PCViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)RunHelloWorld:(id)sender
{
objHelloWorld = [[HelloWorld_M alloc]init];
[self.view addSubview: [objHelloWorld CreateTextView:[objHelloWorld CallCPP]]] ;
}
@end
相关文章:
- 对于四轴飞行器,PID中I控制器的理想值应该是多少
- 如何集成 HID USB 控制器?
- 编译 libfluid 样本控制器时对"event_base_del_virtual"的未定义引用
- 更高效地在微控制器上对C++进行基准测试
- 如何修复 Arduino LED 串控制器的代码?
- 如何在 Windows 中通过 SSL 端口枚举域控制器
- 如何使用 c++ 在命令行中创建一个简单的字符控制器?
- 为什么玩家控制器"own"偏航俯仰和滚动,但角色"owns"它的位置?
- 在虚幻引擎中使用运动控制器组件,C++而不是蓝图
- 哗啦��错误:无法识别任何一组可以驱动指定关节的控制器
- 微控制器的首次 gcc 链接器脚本编译但不运行
- 对控制器类的 WorkerScript 访问
- SDL 2 无法打开控制器,但已识别操纵杆
- 将信号从工作线程类连接到控制器类 - QThreads
- 在OMNet上实现SDN控制器
- SDL2_pollevent() 控制器 dpad 连续保持?
- C++微控制器全局类/辛格尔顿?
- 工作器/控制器多线程和接口类
- 我在微控制器STM32F373发现中点亮LED的问题
- 访问数据从c++函数到UITextView控制器